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 |
Re:望poj想codeforce那样提供相关测试数据,WA的人也好改!!!!In Reply To:望poj想codeforce那样提供相关测试数据,WA的人也好改!!!! Posted by:13107222 at 2012-07-30 15:40:44 以下是错误代码: #include<iostream> #include<cstring> #include<cstdlib> using namespace std; struct worker{ int l,p,s; }s[105]; int dp[105][16005]; int d[16005],l,r; int cmp(const void *a,const void *b) { return (*(worker *)a).s-(*(worker *)b).s; } int main() { int i,j,k,n,m,ll,rr,dat; while(cin>>n>>m) { for(i=1;i<=m;i++) cin>>s[i].l>>s[i].p>>s[i].s; qsort(s+1,m,sizeof(s[0]),cmp); for(i=0;i<=n;i++) dp[0][i]=0; for(i=1;i<=m;i++) { ll=s[i].s-s[i].l; if(ll<0) ll=0; rr=s[i].s+s[i].l-1; if(rr>n) rr=n; for(j=0;j<=n;j++) dp[i][j]=dp[i-1][j]; l=0; r=-1; for(j=ll;j<s[i].s;j++) { while(r>=l&&(dp[i-1][j]+(s[i].s-j)*s[i].p>=dp[i-1][d[r]]+(s[i].s-d[r])*s[i].p)) --r; d[++r]=j; } for(j=s[i].s;j<=rr;j++) { if(j-d[l]>s[i].l) ++l; dat=dp[i-1][d[l]]+(j-d[l])*s[i].p; if(dat>dp[i][j]) dp[i][j]=dat; } for(j=rr+1;j<=n;j++) dp[i][j]=dp[i][rr]; } printf("%d\n",dp[m][n]); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator