Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:brute forceIn Reply To:Re:brute force Posted by:ysjjovo at 2011-03-13 21:43:14 > dp[n][s]为n个数字和为s的方案数 > 则转移方程:dp[n+1][s+i]+=dp[n][s] -1<i<10 > 代码: > #include<iostream> > using namespace std; > int main(){ > int n; > cin>>n; > if(n&1){ > cout<<0<<endl; > return 0; > } > int i,j,k; > int dp[6][9*5+1]; > int max=9; > memset(dp,0,sizeof(dp)); > fill(dp[1],dp[1]+10,1); > for(i=1;i<n/2;i++){ > for(j=0;j<=max;j++){ > for(k=0;k<=9;k++){ > dp[i+1][j+k]+=dp[i][j]; > } > } > max+=9; > } > int ans=0; > for(j=0;j<=max;j++){ > ans+=(dp[i][j]*dp[i][j]); > } > cout<<ans<<endl; > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator