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 |
ms都是递归的...贴个非递归的dp#include <iostream> using namespace std; const int MAXN = 11; int f[MAXN][MAXN];//苹果数, 盘子数 int dp(int n, int m){ if(n > m) n = m; int i, j; for(i = 0; i <= m; ++i) f[i][1] = 1; for(j = 0; j <= n; ++j) f[0][j] = 1; for(i = 1; i <= m; ++i) for(j = 2; j <= n; ++j){ f[i][j] = f[i][j-1]; if(i >= j) f[i][j] += f[i-j][j]; } return f[m][n]; } int main(){ int T, n, m; scanf("%d", &T); while(T--){ scanf("%d%d", &m, &n); printf("%d\n", dp(n, m)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator