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 |
提供两种代码,仅供参考哈~~~int t, n, m, dp[15][15]; inline int DP(int x, int y) { if (~dp[x][y])return dp[x][y]; if (x == 1 || y == 0)return dp[x][y] = 1; if (x > y)return dp[x][y] = DP(y, y); return dp[x][y] = DP(x - 1, y) + DP(x, y - x); } signed main(void) { memset(dp, -1, sizeof(dp)); for (scanf("%d", &t); t; t--) { scanf("%d%d", &m, &n); printf("%d\n", DP(n, m)); } } 这应该算是正解吧,N^2的优秀算法??? int t, n, m, dp[15][15][15], ans[15][15]; signed main(void) { memset(dp, 0, sizeof(dp)), dp[0][0][0] = 1; for (int i = 0; i <= 10; i++) for (int j = 0; j <= 10; j++) for (int k = 0; k <= j; k++) for (int l = k; j + l <= 10; l++) dp[i + 1][j + l][l] += dp[i][j][k]; for (n = 1; n <= 10; n++)for (m = 1; m <= 10; m++) { ans[n][m] = 0; if (m == 0) { ans[n][m] = 1; continue; } for (int i = 0; i <= 10; i++)ans[n][m] += dp[n][m][i]; } for (scanf("%d", &t); t; t--)scanf("%d%d", &n, &m), printf("%d\n", ans[m][n]); } 哈哈,这是自己YY的快速打表,省脑子,四个for看着就爽啊,复杂度嘛,那不重要___ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator