POJ 1260 Pearls

版权声明:听说这里让写版权声明~~~ https://blog.csdn.net/m0_37691414/article/details/82729205
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N  = 1100;
int dp[N], sum[N], a[N], p[N];
int main(){
	int t, n;
	scanf("%d", &t);
	while(t--){
		memset(a, 0, sizeof(a));
		memset(dp, 0, sizeof(dp));
		memset(p, 0, sizeof(p));
		memset(sum, 0, sizeof(sum));
		scanf("%d", &n);
		for(int i = 1; i <= n; ++i){
			scanf("%d%d", &a[i], &p[i]);
			sum[i] = sum[i - 1] + a[i];
		}
		for(int i = 1; i <= n; ++i){
			dp[i] = (a[i] + 10)*p[i] + dp[i - 1];
			for(int j = 0; j < i; ++j)
				dp[i] = min(dp[i], (sum[i] - sum[j] + 10)*p[i] + dp[j]);
		}
		printf("%d\n", dp[n]);
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/m0_37691414/article/details/82729205