| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
最水的dp题#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int cases;
scanf("%d", &cases);
for(int ii = 0; ii < cases; ii++){
int N;
scanf("%d", &N);
int bfh[110];
bfh[0] = 0;
int price[110], num[110];
for(int i = 1; i <= N; i++){
scanf("%d%d", &num[i], &price[i]);
bfh[i] = bfh[i-1] + num[i];
}
int ans[110];
ans[0] = 0;
ans[1] = (num[1] + 10) * price[1];
for(int i = 2; i <= N; i++){
int mn = 2147483647;
for(int j = i; j > 0; j--){
int temp = ans[j-1] + (bfh[i]-bfh[j-1]+10) * price[i];
if(temp < mn) mn = temp;
}
ans[i] = mn;
}
printf("%d\n", ans[N]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator