这里是简介
分析
经过打表发现,所填的数在区间$[k,k+15]$之间,所以可以暴枚…
为了节省版面,给出$n=5$和$n=6$的情况,其它情况类似
代码
#include <cstdio>
#include <cstring>
typedef long long ll;
ll a[20], n, ans, add, reans[1000010][10], p[1000010], m, k;
bool b[1000010];
bool judge() {
for (register ll i = n + 1; i <= n * 2; ++i)
a[i] = a[i - n];
for (register ll i = 1; i <= n << 1; ++i)
p[i] = p[i - 1] + a[i];
for (register ll i = 1; i <= p[n << 1]; ++i)
b[i] = 0;
for (register ll i = 1; i <= n; ++i)
for (register ll j = i; j <= i + n - 1; ++j)
b[p[j] - p[i - 1]] = true;
ll i = m;
while (b[i]) i++;
i--;
if(i > ans) {
add = 0, ans = i;
return true;
}
return i == ans;
}
int main() {
scanf ("%lld%lld%lld", &n, &m, &k);
if(n==5) {
for(a[1] = k; a[1] <= m; ++a[1])
for(a[2] = a[1]; a[2] <= k + 15; ++a[2])
for(a[3] = a[1]; a[3] <= k + 15; ++a[3])
for(a[4] = a[1]; a[4] <= k + 15; ++a[4])
for(a[5] = a[1]; a[5] <= k + 15; ++a[5])
if(judge())
reans[++add][0]=a[1], reans[add][1]=a[2], reans[add][2]=a[3], reans[add][3]=a[4], reans[add][4]=a[5];
} else {
for(a[1] = k; a[1] <= m; ++a[1])
for(a[2] = a[1]; a[2] <= k + 15; ++a[2])
for(a[3] = a[1]; a[3] <= k + 15; ++a[3])
for(a[4] = a[1]; a[4] <= k + 15; ++a[4])
for(a[5] = a[1]; a[5] <= k + 15; ++a[5])
for(a[6] = a[1]; a[6] <= k + 15; ++a[6])
if(judge())
reans[++add][0] = a[1], reans[add][1] = a[2], reans[add][2] = a[3], reans[add][3] = a[4], reans[add][4] = a[5], reans[add][5] = a[6];
}
printf("%lld\n",ans);
for(register ll i = 1; i <= add; ++i) {
for(register ll j = 0; j < n; ++j)
printf("%d ", reans[i][j]);
puts("");
}
return 0;
}