Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

提供两种代码,仅供参考哈~~~

Posted by yousiki at 2016-07-28 17:42:48 on Problem 1664
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator