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

竟然是数组开小了,WA了好多次啊,贴一个

Posted by yd1002 at 2013-05-10 20:54:35 on Problem 2063
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int dp[100110];//竟然是数组太小了,WA了好多次
struct node
{
    int cost;
    int value;
}s[1500];
int main()
{
    int t,i,d,sum,year,maxf,j,k,l,sy;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        scanf("%d%d%d",&sum,&year,&d);
        sy=sum/1000;
        for (i=1;i<=d;++i)
        {
            scanf("%d%d",&s[i].cost,&s[i].value);
            s[i].cost=s[i].cost/1000;
        }
        for (i=1;i<=year;++i)
        {
            memset(dp,0,sizeof(dp));
            maxf=-1;
            for (j=1;j<=d;++j)
            for (k=s[j].cost;k<=sy;++k)
            {
                dp[k]=max(dp[k],dp[k-s[j].cost]+s[j].value);
            }
            sum=sum+dp[sy];
            sy=sum/1000;
        }
        printf ("%d\n",sum);
    }
    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