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

I don't know why i got W/A.

Posted by jrj325 at 2007-06-15 20:46:22 on Problem 3093
#include<stdio.h>
#include<algorithm>

FILE *fo = fopen("input.txt","r");
FILE *fp = fopen("output.txt","w");
int D[35][1010]={0};
int rotate[1010]={0};
int l[35]={0};
bool sortf(int a,int b){
	return a > b;
}
int main(){
	int T;
	fscanf(stdin,"%d",&T);
	int i,j,k;
	int n,m;
	int total = 0;
	int ches = 0;
	for(k=0;k<T;k++){
		n = m = 0;
		fscanf(stdin,"%d %d",&n,&m);
		for(i=0;i<n;i++){
			fscanf(stdin,"%d",&l[i]);
		}
		std::sort(l,l+n,sortf);
		rotate[n] = 0;
		for(i=n-1;i>=0;i--){
			rotate[i] = rotate[i+1] + l[i];
		}
		total = 0;

		ches = rotate[0];
		if(ches <= m)total ++;

		D[0][0] = 1;
		if(l[0] <= m){
			D[0][l[0]] = 1;
		}
		ches = rotate[1] ;
		if((m-ches) < l[0] && ches <= m){
			total ++;
		}
		l[0] = 0;
		for(i=1;i<n;i++){
			for(j=0;j<=m;j++){
				if(D[i-1][j] != 0){
					if(j + l[i] <= m){
						D[i][j+l[i]] += D[i-1][j];
					}
				}
				D[i][j] += D[i-1][j]; 
				ches = rotate[i+1] + j;
				if( (m-ches) < l[i]  && ches <= m){
					total += D[i-1][j];
				}
			}
			l[i] = 0;
		}
		for(i=0;i<n;i++){
			for(j=0;j<=m;j++){
				D[i][j] = 0;
			}
			rotate[i] = 0;
		}
		rotate[n] = 0;
		fprintf(stdout,"%d %d\n",k+1,total);
	}
	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