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 |
我很水~~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator