标签:
说有个人钓鱼,好多湖,湖里的鱼从开始钓计时,每
直接
/* **********************************************
File Name: 1163.cpp
Auther: zhengdongjian@tju.edu.cn
Created Time: 2015/8/26 星期三 下午 1:08:38
*********************************************** */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0xfffffff;
const int MAX_T = 207;
const int MAX_L = 26;
struct State {
int i, j, k;
};
int dp[MAX_L][MAX_T][MAX_T];
State dad[MAX_L][MAX_T][MAX_T];
int daisy[MAX_L];
int f[MAX_L], d[MAX_L], t[MAX_L];
/*
* dp[i][j][0] = dp[i-1][j - t_{i-1}][..]
* dp[i][j][k] = max{dp[i][j - 1][k - 1] + max(0,fi-(k-1)di)}
*/
int main() {
int n, h;
bool black = false;
while (~scanf(" %d", &n) && n) {
scanf(" %d", &h);
h *= 12;
for (int i = 1; i <= n; ++i) {
scanf(" %d", f + i);
}
for (int i = 1; i <= n; ++i) {
scanf(" %d", d + i);
}
for (int i = 1; i < n; ++i) {
scanf(" %d", t + i);
}
t[0] = 0;
//memset(dp, 0, sizeof(dp));
for (int k = 0; k <= n; ++k) {
for (int i = 0; i <= h; ++i) {
for (int j = 0; j <= h; ++j) {
dp[k][i][j] = -INF;
}
}
}
dp[0][0][0] = 0;
dad[0][0][0] = (struct State){-1, -1, -1};
//memset(dp[0], 0, sizeof(dp[0]));
int use = 0;
for (int i = 1; i <= n; ++i) {
for (int j = use; j <= h; ++j) {
for (int k = 0; k <= h - use; ++k) {
if (k == 0) {
if (j < t[i - 1]) continue;
for (int r = 0; r <= h; ++r) {
if (dp[i - 1][j - t[i - 1]][r] > dp[i][j][k]) {
dp[i][j][k] = dp[i - 1][j - t[i - 1]][r];
dad[i][j][k] = (struct State){i - 1, j - t[i - 1], r};
}
}
} else {
if (j) {
int vl = dp[i][j - 1][k - 1] + max(0, f[i] - (k - 1) * d[i]);
if (dp[i][j][k] < vl) {
dp[i][j][k] = vl;
dad[i][j][k] = (struct State){i, j - 1, k - 1};
}
}
}
}
}
use += t[i];
}
int ans = 0;
P mom = P(0, 0);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= h; ++j) {
if (dp[i][h][j] > ans) {
ans = dp[i][h][j];
mom = P(i, j);
}
}
}
memset(daisy, 0, sizeof(daisy));
State now = (struct State){mom.first, h, mom.second};
//daisy[mom.first] = mom.second;
while (now.i != -1) {
daisy[now.i] = max(daisy[now.i], now.k);
now = dad[now.i][now.j][now.k];
}
int sum = 0;
for (int i = 1; i <= n; ++i) {
sum += daisy[i];
}
for (int i = n; i >= 1; --i) {
if (daisy[i]) {
for (int j = i - 1; j >= 1; --j) {
sum += t[j];
}
break;
}
}
daisy[1] += h - sum > 0 ? h - sum : 0;
if (black) puts("");
for (int i = 1; i < n; ++i) {
printf("%d, ", daisy[i] * 5);
}
printf("%d\n", daisy[n] * 5);
printf("Number of fish expected: %d\n", ans);
black = true;
}
return 0;
}
版权声明:那泥烤去看鸭o o
标签:
原文地址:http://blog.csdn.net/bit_line/article/details/48002011