http://acm.nyist.net/JudgeOnline/problem.php?pid=651

描述
We have a rope whose length is L. We will cut the rope into two or more parts, the length of each part must be an integer, and no two parts have the same length.
  Your task is to calculate there exists how many results after the cutting. We say two results are different if and only if there is at least one part, which we can find in one result but can not find in the other result

输入
There is an integer T (1 <= T <= 50000) in the first line, which indicates there are T test cases in total.
  For each test case, there is only one integer L (1 <= L <= 50000) which has the same meaning as above.
输出
For each test case, you should output the correct answer of the above task in one line.
  Because the answer may be very large, you should just output the remainder of it divided by 1000000 instead
样例输入
3
2
3
6
样例输出
0
1
3

/*
1+2+3+4+...+k=(k+1)*k/2
N = 500000 (长度)
解得k = 316
dp[n][k]表示长度为n的线段分解成k段的方案数。
有2种情况:
1.有长度为1的:dp[n-k][k-1]
2.没有长度为1的;每段的长度减1后,与dp[n-k][k]的方案数相同 所以dp[n][k] = (dp[n-k][k-1]+dp[n-k][k])%Mod
观察dp,dp[n][k]需要的是左上角和上的信息。
所以递归基础是k=2和n=2的情况。(第一行第一列)
n=2, dp[2][i] = 0
k=2, dp[i][2] = (i-1)/2 ans[i]就是对dp[i][*]求和.
*/
#include <iostream>
#include <cstring>
using namespace std; #define N 50002
#define K 316
#define Mod 1000000
int m;
int n;
int dp[N][K];
int ans[N]; void pre()
{
ans[] = ans[] = ; for (int i = ; i < K; ++i)
dp[][i] = ;
for (int i = ; i < N; ++i)
dp[i][] = (i-)/; for (int i = ; i < N; ++i)
{
for (int j = ; j < K; ++j)
{
if (i-j >= )
dp[i][j] = (dp[i-j][j-] + dp[i-j][j])%Mod;
}
} for (int i = ; i < N; ++i)
for (int j = ; j < K; ++j)
ans[i] = (ans[i]+dp[i][j])%Mod;
} int main()
{
pre(); cin >> m; while (m--)
{
cin >> n; cout << ans[n] << endl;
}
}
05-29 01:11