#include<iostream>
#include <limits.h>
using namespace std;
//***************************常量定义***************************
//**************************题目变量****************************
//全局变量全部初始化为0
int a[110];
int p[110];
int e[110];
int testcase;
int typecase;
int result[110];
//*************************算法变量*****************************
inline int sum(int i,int j)
{
int total=0;
for(int k=i;k<=j;k++)
total+=a[k];
total=(total+10)*p[j];
return total;
}
int dp()
{
e[1]=(a[1]+10)*p[1];
for(int i=2;i<=typecase;i++)
{
int cost=LONG_MAX;
for(int j=0;j<i;j++)
{
if(cost>=(e[j]+sum(j+1,i)))
cost=e[j]+sum(j+1,i);
}
e[i]=cost;
}
return e[typecase];
}
int main()
{
scanf("%d", &testcase);
for(int i=1;i<=testcase;i++)
{
scanf("%d",&typecase);
for(int j=1;j<=typecase;j++)
{
scanf("%d%d",&a[j],&p[j]);
}
dp();
printf("%d\n", dp());
}
}
注:本来定义LONG_MAX=9999;提交后显示Wrong Answer
所以,现在定义极大值,最好是直接
#include <limits.h>
用系统自定义的<span style="background-color: rgb(240, 240, 240);">LONG_MAX。</span>