母函数
http://acm.hdu.edu.cn/showproblem.php?pid=1028
将数字拆分 看有多少种组合
#include <iostream> using namespace std; typedef long long LL; const int N=121; //题目所求数字和的最大值 const int maxn=125; //你所拥有的数字的值 LL c1[N],c2[N]; //c1 最终合并的多项式 c2临时合并的多项式 int n=121; void init() { c1[0]=1; for(int i=1;i<=maxn;i++) //遍历你所拥有的数 { for(int j=0;j<N;j+=i) //每次加上你所拥有的数 { for(int k=0;j+k<N;k++) //从x^0到x^N遍历一遍 { c2[j+k]+=c1[k]; } } for(int j=0;j<N;j++) { c1[j]=c2[j]; c2[j]=0; } } } void solve() { int n; cin>>n; cout<<c1[n]<<endl; return ; } int main() { // int t; // cin>>t; // while(t--) // { // solve(); // } init(); while(scanf("%d", &n) != EOF){ printf("%I64d\n", c1[n]); } return 0; }
http://acm.hdu.edu.cn/showproblem.php?pid=1398
航电
你有x^2的钞票 看能组成多少种n
#include <iostream> using namespace std; typedef long long LL; const int N=300+5; //题目所求数字和的最大值 const int maxn=18; //你所拥有的数字的值 LL c1[N],c2[N]; //c1 最终合并的多项式 c2临时合并的多项式 LL c[maxn]; int n; void init() { for(int i=1;i<=maxn;i++) { c[i]=i*i; } c1[0]=1; for(int i=1;i<=maxn;i++) //遍历你所拥有的数 { for(int j=0;j<N;j+=c[i]) //每次加上你所拥有的数 { for(int k=0;j+k<N;k++) //从x^0到x^N遍历一遍 { c2[j+k]+=c1[k]; } } for(int j=0;j<N;j++) { c1[j]=c2[j]; c2[j]=0; } } } void solve() { int n; cin>>n; cout<<c1[n]<<endl; return ; } int main() { // int t; // cin>>t; // while(t--) // { // solve(); // } init(); while(scanf("%d", &n) != EOF&&n){ printf("%I64d\n", c1[n]); } return 0; }
吾志所向
一往无前
愈挫愈奋
再接再励
——卓

浙公网安备 33010602011771号