Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

最水的dp题

Posted by KatrineYang at 2016-08-22 02:18:02 on Problem 1260
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator