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[i]=10000000;你就是WA,换成999999999就AC. #include<iostream> using namespace std; int mini(int a,int b) { if(a<b) return a; else return b; } int dp[105]; int sum[105]; int pri[105]; int num[105]; int main() { int T,n,i,j; cin>>T; while(T!=0) { cin>>n; for(i=1;i<=n;i++) cin>>num[i]>>pri[i]; sum[0]=0; for(i=1;i<=n;i++) sum[i]=sum[i-1]+num[i]; dp[0]=0; for(i=1;i<=n;i++) { dp[i]=999999999; for(j=0;j<=i;j++) dp[i]=mini(dp[i],dp[j]+(sum[i]-sum[j]+10)*pri[i]); } cout<<dp[n]<<endl; T=T-1; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator