标签:
排队购票
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1264 Solved: 808
2 1 2 1 1
0 1
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int N = 30 + 5 ; 6 int dp[N][N]; 7 int T ; 8 int n,m; 9 int main() 10 { 11 //freopen ("a.txt" , "r" , stdin ) ; 12 scanf("%d",&T); 13 while( T --) 14 { 15 memset(dp,0,sizeof(dp)); 16 scanf("%d%d",&n,&m); 17 if(n < m ) { 18 puts ("0") ; 19 continue ; 20 } 21 for(int i = 0 ; i <= n ; i++) 22 { 23 for(int j = 0 ; j <= max(i,m) ; j ++) 24 { 25 if(i == 0 ) dp[i][j] = 0 ; 26 else if(j == 0 && i != 0 )dp[i][j] = 1 ; 27 else 28 { 29 dp[i][j] = dp[i-1][j]; 30 if(i > j-1) dp[i][j] += dp[i][j-1]; 31 } 32 } 33 } 34 35 printf("%d\n",dp[n][m]); 36 } 37 return 0 ; 38 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4391674.html