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 |
发现不能减少成本的数据就停止。// 还是沿用大家的dp方法,有个小改进,通过对比累加减少的金额,一旦发现不能减少金额的数据,即可停止 #include "stdio.h" #include "string.h" const int size=105; struct item{ int num,p; } ct[size]; int s[size]; int _max(int a,int b){ if(a>b) return a; return b; } int main(){ int cost,ts,ts1,u; int t,c; int i,j; scanf("%d",&t); while(t>0){ t--; scanf("%d",&c); cost=0; for(i=1;i<=c;i++){ scanf("%d%d",&ct[i].num,&ct[i].p); cost+=(ct[i].num+10)*ct[i].p; } memset(s,0,sizeof(s)); for(i=1;i<=c;i++){ ts=0; s[i]=s[i-1]; if(i>1) { for(j=i-1;j>=1;j--){ ts1=ts; u=(ct[j].num+10)*ct[j].p-ct[j].num*ct[i].p; if(u<=0) break; ts+=u; s[i]=_max(s[i],_max(ts1+s[j],ts+s[j-1])); } } } printf("%d\n",(cost-s[c])); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator