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

是不是有什么trick? 我怎么就一直wrong?

Posted by bmexue at 2006-12-26 10:25:19 on Problem 3093
#include <iostream>
using namespace std;

int V,D,d[31],sum[31];
unsigned int dp[31][1001];
void work()
{
   memset(dp,0,sizeof(dp));
   for(int i=1;i<=V;i++)
   {
	   for(int j=1;j<=D;j++)
	   {
		   if( j>= sum[i] )
			   dp[i][j] = 1;
		   else 
		   {
			   if( j>= d[i] )
			   {
				   if( dp[i-1][j-d[i]] >0 )
				       dp[i][j] = dp[i-1][j-d[i]] + dp[i-1][j];
				   else 
			           dp[i][j] = 1 + dp[i-1][j];
               }
			   else
				   dp[i][j] = dp[i-1][j];
		   }
	   }
   }
}

int main()
{
    freopen("C:\\ACMData.txt","r",stdin);
	int T,i,k=1; scanf("%d",&T);
	while(T)
	{
	    scanf("%d%d",&V,&D);
		for(i=1;i<=V;i++) scanf("%d", &d[i]);
        sum[0] =0;
		for(i=1;i<=V;i++) sum[i] = sum[i-1] + d[i];
        work(); printf("%d %u\n",k++,dp[V][D]);

		T--;
	}
    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