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

吐个槽

Posted by kingofkiller at 2013-04-25 21:01:10 on Problem 1260
这个题目的初始化很要命啊,就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:
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