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 javaman at 2005-08-22 04:34:26 on Problem 2430
从晚上做到凌晨  后来一直wa  请求帮助。(找不到错误,也测试不出错误) 感谢。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int ppmm[]={0,1,1,2};

typedef struct {
int x,y;
} COW;


typedef struct {
int y,s;
} STATE;

COW cow[1005];
STATE a[1005];
int dp[1005][1005][4];

int cmp(const void *a,const void *b) {
COW *p=(COW*) a,*q=(COW*) b;
	return p->y-q->y;
}
。
int cost(int x,int y) {
	if ((x|y)!=x)
		return -1;
	return ((x<3)?1:2);
}

int main() {
int m,n,i,j,k,x,y,may,c;


	while (scanf("%d%d%d",&n,&k,&i)!=EOF) {
		for (i=0;i<n;++i) {
			scanf("%d%d",&cow[i].x,&cow[i].y);
		}
		qsort(cow,n,sizeof(COW),cmp);
		m=j=a[0].s=0;
		for (i=0;i<n;++i) 
			if (cow[i].y!=j) {
				a[++m].y=j=cow[i].y;
				a[m].s=(1<<(2-cow[i].x));
			}
			else 
				a[m].s=3;
			
		if (k>=m) {
			printf("%d\n",n);
			continue;
		}

		a[0].y=a[1].y-1;
		memset(dp,0xff,sizeof(dp));
		dp[0][0][1]=dp[0][0][2]=dp[0][0][3]=0;
		
		for (i=1;i<=k;++i) { //矩形数
			for (j=i;j<=m;++j) {  //有效列数
				for (x=1;x<=3;++x) { //现在状态
					if ((c=cost(x,a[j].s))<0)
						continue;
					if (dp[i][j-1][x]>=0)
						dp[i][j][x]=c+(a[j].y-a[j-1].y-1)*ppmm[x]+dp[i][j-1][x];
					for (y=1;y<=3;++y) {
						if (dp[i-1][j-1][y]>=0) {
							may=c+dp[i-1][j-1][y];
							if ((dp[i][j][x]<0) || (may<dp[i][j][x]))
								dp[i][j][x]=may;
						}
					}
				}
			}
		}
		may=dp[k][m][1];
		for (i=2;i<=3;++i)
			if ((may<0) || ((may>dp[k][m][i]) && (dp[k][m][i]>=0)))
				may=dp[k][m][i];
		printf("%d\n",may);
	}
	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