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

为什么C++过了,G++却过不了????

Posted by celia01 at 2011-05-28 00:19:10 on Problem 1276
为什么C++过了,G++却过不了????,(代码如下,C++已AC)

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;

int main(){
	int cash, n;
	int c[100], f[100005];
	int i, j, k;
	int num, cost, d;
	
	while(scanf("%d",&cash)!=EOF){
		cin>>n;
		d = 1;
		for (i=1;i<=n;i++){
			j=1;
			cin>>num>>cost;
			while(j<=num){
				c[d++] = j*cost;
				num-=j;
				j*=2;
			}
			if (num>0){
				c[d++] = num*cost;
			}
		}
		memset(f,0,sizeof(f));
		for (i=1;i<=d-1;i++){
			if (cash>=c[i]){
				for (k=cash;k>=c[i];k--)
					f[k] = (f[k] > (f[k-c[i]]+c[i]) )? f[k]:(f[k-c[i]]+c[i]);
			}
		
		}
		cout<<f[cash]<<endl;
	}
	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