AcWing 313. 花店橱窗
原题链接
简单
作者:
wjie
,
2020-07-15 17:22:29
,
所有人可见
,
阅读 612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int N = 1e2 + 5;
int f[N][N], w[N][N];
int main()
{
int F, V;
scanf("%d%d", &F, &V);
for (int i = 1; i <= F; ++i)
{
for (int j = 1; j <= V; ++j)
{
scanf("%d", &w[i][j]);
}
}
memset(f, -0x3f, sizeof(f));
f[1][0] = 0;
f[1][1] = w[1][1];
for (int i = 2; i <= V; ++i)
{
f[i][0] = f[i-1][0];
for (int j = 1; j <= F; ++j)
{
f[i][j] = max(f[i-1][j], f[i-1][j-1]+w[j][i]);
}
}
printf("%d\n", f[V][F]);
int x = V, y = F;
stack<int> res;
while (x > 0 && y > 0)
{
if (f[x][y] == f[x-1][y]) x--;
else
{
res.push(x);
x--, y--;
}
}
while (!res.empty())
{
printf("%d ", res.top());
res.pop();
}
return 0;
}