Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位大神告诉我为什么wa啊?#include<stdio.h> #include<stdlib.h> #include<iostream> #include<algorithm> #include<string.h> #include<math.h> using namespace std; int ff[40001]; struct node { int h; int c; int a; }stone[500]; bool cmp(node a,node b) { return a.a<b.a; } int max(int a,int b) { return a>b?a:b; } void zeroone(int f[],int c,int w,int ma) { for(int i=ma;i>=c;i--) { f[i]=max(f[i],f[i-c]+w); } } void comp(int f[],int c,int w,int ma) { for(int i=c;i<=ma;i++) { f[i]=max(f[i],f[i-c]+w); } } void mul(int f[],int c,int w,int m,int ma) { if(c*m>=ma) { comp(f,c,w,ma); return; } int k=1; while(k<m) { zeroone(f,k*c,k*w,ma); m=m-k; k=k*2; } zeroone(f,c*m,w*m,ma); } int main() { int i,j,k,l,m,n; scanf("%d",&k); for(i=0;i<k;i++)scanf("%d%d%d",&stone[i].h,&stone[i].a,&stone[i].c); sort(stone,stone+k,cmp); int mmax=stone[k-1].a; for(i=0;i<=mmax;i++)ff[i]=0; for(i=0;i<k;i++) { if(stone[i].h>stone[i].a)continue; mul(ff,stone[i].h,stone[i].h,stone[i].c,stone[i].a); } printf("%d\n",ff[mmax]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator