// Problem#: 5003
// Submission#: 2053786
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<algorithm>
#include<cstring>
#define MAXN 1000007
using namespace std;
int a[510];
void solve();
int main()
{
solve();
int N,i;
cin>>N;
while( N--)
{
cin>>i;
//ios_base::sync_with_stdio(false);
cout<<a[i]<<endl;
}
}
void solve()
{
memset(a,0,sizeof(a));
a[0]=1;
for (int i=2; i<=501; i++)
for (int j=i; j<=501; j++)
{
a[j] += a[j - i];
if ( a[j] >= MAXN )
a[j] -= MAXN;
}
}
弱菜昨天想了一下没想出来,看了赵牛的解法。然后发现这题去年5月做过了,而且解法更简洁...不知道是不是来自星爷...
http://soj.me/viewsource.php?cid=540&sid=1006808