Sicily 1011——动态规划
1 // Problem#: 1011 2 // Submission#: 2190848 3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ 5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University 6 //dp[i][j] = sum(dp[i-1][k]), 1 <= k <= j/2 7 #include <iostream> 8 #include <cstring> 9 using namespace std; 10 11 const int N = 11; 12 const int M = 2001; 13 long long dp[N][M]; 14 15 int main() 16 { 17 int cases,n,m; 18 long long result; 19 cin>>cases; 20 for(int count = 1;count <= cases;count++) 21 { 22 cin>>n>>m; 23 memset(dp, 0, sizeof(dp)); 24 for(int i=1;i<=m;i++) 25 dp[1][i] = 1; 26 for(int i=2;i<=n;i++) 27 for(int j=1;j<=m;j++) 28 for(int k=1;k<=j/2;k++) 29 dp[i][j] += dp[i-1][k]; 30 result = 0; 31 for(int i=1;i<=m;i++) 32 result += dp[n][i]; 33 /*for(int i=1;i<=n;i++) 34 { 35 for(int j=1;j<=m;j++) 36 cout<<dp[i][j]<<' '; 37 cout<<endl; 38 }*/ 39 cout<<"Case "<<count<<": n = "<<n<<", m = "<<m<<", # lists = "<<result<<endl; 40 } 41 return 0; 42 }