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为何WA?

Posted by 096040528 at 2011-03-13 18:24:26 on Problem 2436
为何无人用DP?
#include <iostream>
#include <vector>
using namespace std;
const int MAXD=20;
const int MAXN=1005;
vector<int>cow[MAXN];
struct node
{
	int m,ans;
	int d[MAXD];
}dp[MAXN];
void copy(int a[],int b[],int n)
{
	for(int i=1;i<=n;i++)
		a[i]=b[i];
}
int main()
{
	int N,D,K,i,j,k,n,x,max;
	dp[0].m=0; dp[0].ans=0;
	memset(dp[0].d,0,sizeof(dp[0].d));
	while(scanf("%d%d%d",&N,&D,&K)!=EOF)
	{
		for(i=1;i<=N;i++)
		{
			dp[i].m=0; dp[i].ans=0;
			cow[i].clear();
			memset(dp[i].d,0,sizeof(dp[i].d));
			scanf("%d",&n);
			while(n--)
			{
				scanf("%d",&x);
				cow[i].push_back(x);
			}
		}
		
		for(i=1;i<=N;i++)//a
		{
			int len=cow[i].size();//a
			for(j=0;j<i;j++)//dp
			{
				int v[MAXD];
				memset(v,0,sizeof(v));
				int cnt=0;
				for(k=0;k<len;k++)//copy vir
				{
					v[cow[i][k]]=1;
					cnt++;
				}
				for(k=1;k<=D;k++)//copy vir
				{
					if(!v[k] && dp[j].d[k])
					{
						v[k]=1;
						cnt++;
					}
				}
				//printf("cnt:%d\n",cnt);
				if(cnt<=K && dp[i].m<dp[j].m+1)//big k
				{
					dp[i].m=dp[j].m+1;
					copy(dp[i].d,v,D);	
					dp[i].ans=cnt;
				}
				else if(cnt<=K && dp[i].m==dp[j].m+1 && cnt<dp[i].ans)
				{
					copy(dp[i].d,v,D);
					dp[i].ans=cnt;
				}
			}
		}
		for(i=1,max=0;i<=N;i++)
		{
			//printf("%d\n",dp[i].ans);
			if(max<dp[i].m)
				max=dp[i].m;
		}
		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