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

贴个DP代码,和我同样写法的注意一个不太容易找的错误

Posted by qddpx at 2012-07-31 10:24:01 on Problem 1276
#include <cstdio>
#include <cstring>
#define MAX 100005
#define MAXN 11

int m, n, nk, dk, vis[MAXN][MAX], usd[MAXN][MAX];

int main() {
	int i, j, max;
	while(scanf("%d%d", &m, &n) != EOF) {
		memset(vis, 0, sizeof(vis));
		vis[0][0] = 1, max = usd[0][0] = 0;
		for(i = 0; i < n; i++) {
			scanf("%d%d", &nk, &dk);
			for(j = 0; j <= m; j++)
				if(vis[i][j]) {
					if(max < j) max = j;
					vis[i+1][j] = 1, usd[i+1][j] = 0;
					if(j + dk <= m && usd[i][j] < nk && !vis[i][j+dk])
						vis[i][j+dk] = 1, usd[i][j+dk] = usd[i][j] + 1;
				}
		}
		printf("%d\n", max);
	}
	return 0;
}

牛牛们请无视。注意如果加一张当前钞票的数额可以在上一层产生就不要覆盖(记录钞票数量),否则当前钞票不够用。

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