fjnu2016-2017 低程 PROBLEM C 汪老司机

动态规划 方程

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <windows.h>
using namespace std;
long a[10010],b[10010],f[10010][20][2];
int main() {
int t;
scanf("%d",&t);
while (t--) {
int n,k;
scanf("%d%d",&n,&k);
for (int i = 1;i <= n; i++) scanf("%I64d",&a[i]);
for (i = 1;i <= n; i++) scanf("%I64d",&b[i]);
for (i = 1;i <= n; i++) {
f[i][0][0] = f[i-1][0][0] + a[i];
f[i][0][1] = f[i-1][0][1] + b[i];
for (int j = 1;j <= k; j++) {
f[i][j][0] = min(f[i-1][j][0]+a[i],f[i-1][j-1][1]+b[i]);
f[i][j][1] = min(f[i-1][j-1][0]+a[i],f[i-1][j][1]+b[i]);
}
}
cout << min(f[n][k][0],f[n][k][1]) << endl;
}
return 0;
}

posted @ 2017-11-06 18:47  Ruohua3kou  阅读(91)  评论(0编辑  收藏  举报