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 sicojuy at 2011-03-17 17:17:53 on Problem 1742
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

bool can_pay[100005]; 
int use_ai[100005];    
int Ai[105], Ci[105];
int n, m, ans;

int coins();

int main()
{
	int i;
	while(scanf("%d%d", &n, &m), n || m)
	{
		memset(can_pay, false, sizeof(can_pay));
		can_pay[0] = true;
		for(i = 0; i < n; ++i)
			scanf("%d", &Ai[i]);
		for(i = 0; i < n; ++i)
			scanf("%d", &Ci[i]);
        coins();
	}
	return 0;
}

int coins()
{
    int i, j;
    ans = 0;
    for(i = 0; i < n; ++i)
    {
        memset(use_ai, 0, sizeof(use_ai));
        for(j = Ai[i]; j <= m; ++j)
        {
                if(!can_pay[j] && can_pay[j - Ai[i]] && use_ai[j - Ai[i]] < Ci[i])
                {
                    can_pay[j] = true;
                    use_ai[j] = use_ai[j - Ai[i]] + 1;
                    ++ans;
                }
        }
    }
    printf("%d\n", ans);
    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