hdu1300 Pearls

#include <stdio.h>
#include <string.h>
#define INF 0x7ffffff
//dp[i]=min(dp[j]+(arr[i]-arr[j]+10)*price[i]
int main()
{
	int n,test,i,j,min,mi;
	int dp[102],arr[102],price[102];
	scanf("%d",&test);
	while(test--)
	{
		scanf("%d",&n);
		arr[0]=0;
		for (i=1;i<=n;i++)
		{
			scanf("%d %d",&mi,&price[i]);
			arr[i]=arr[i-1]+mi;
		}
		memset(dp,0,sizeof(dp));
		for (i=1;i<=n;i++)
		{
			min=INF;
			for (j=0;j<i;j++)
			{
				if(dp[j]+(arr[i]-arr[j]+10)*price[i]<min)
					min=dp[j]+(arr[i]-arr[j]+10)*price[i];
			}
			dp[i]=min;
		}
		printf("%d\n",dp[n]);
	}
	return 0;
}

你可能感兴趣的:(hdu1300 Pearls)