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 yingxiang720 at 2011-03-30 01:21:50 on Problem 1276
#include <iostream>
using namespace std;

struct mac
{
    int n;
    int d;
}nd[11];
bool dp[100010];

int main()
{
    int i,j,n,cash,k,cmax;
    while(scanf("%d%d",&cash,&n) != EOF)
    {
        for(i = 0;i < n;i++)    scanf("%d%d",&nd[i].n,&nd[i].d);
        if(cash == 0 || n == 0)
        {
            printf("0\n");
            continue;
        }
        memset(dp,0,sizeof(dp));
        dp[0] = true;
        for(i = 0,cmax = 0;i < n;i++)
            for(j = cmax;j >= 0;j--)
                if(dp[j])
                    for(k = 1;k <= nd[i].n;k++)
                    {
                        int temp = j + k*nd[i].d;
                        if(temp > cash) break;
                        dp[temp] = true;
                        if(temp > cmax) cmax = temp;
                    }
        printf("%d\n",cmax);
    }
    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