题目:http://acm.tju.edu.cn/toj/showp1496.html
找到状态转移方程,然后枚举处理......
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
int ai[101], pi[101], dp[101], sum[101];
int main() {
int cas, n;
scanf("%d", &cas);
while (cas--) {
memset(dp, 0, sizeof(dp));
scanf("%d", &n);
sum[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", ai + i, pi + i);
sum[i] = sum[i - 1] + ai[i];
dp[i] = (sum[i] + 10) * pi[i];
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
dp[i] = min(dp[i], (sum[i] - sum[j] + 10) * pi[i] + dp[j]);
printf("%d\n", dp[n]);
}
}