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

我很水~~

Posted by 306457592 at 2009-07-22 10:56:42 on Problem 1784
#include <iostream>
using namespace std;
int main()
{
	int n, i, j, k, temp, l;
	int p[205], q[205], v[205], w[205];
	unsigned long int a[205][205];

	scanf("%d", &n);
	while (n != 0) {
		v[0] = 0;
		for (i=1; i <= n; i++) {
			scanf("%d", &p[i]);
			v[i] = v[i-1] + p[i];
		}
		scanf("%d", &q[0]);
		w[0] = q[0];
		for (i=1; i <= n; i++) {
			scanf("%d", &q[i]);
			w[i] = w[i-1] + q[i];
		}
		for (i=1; i <= n; i++) {
			for (j=1; j <= n; j++) {
				a[i][j] = 100000000;
			}
		}
		for (i=1; i <= n+1; i++) {
			a[i][i-1] = q[i-1];
		}
		for (l=1; l <= n; l++) {
			for (i=1; i <= n-l+1; i++) {
				j = i + l - 1;
				for (k=i; k <= j; k++) {
					temp = a[i][k-1] + a[k+1][j] + (v[j]-v[i]+p[i]) + (w[j]-w[i-1]+q[i-1]);
					if (temp < a[i][j]) 
						a[i][j] = temp;
				}
			}
		}
		printf("%d\n", a[1][n]-w[n]);
		scanf("%d", &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