-
Notifications
You must be signed in to change notification settings - Fork 4
/
104.cpp
43 lines (41 loc) · 859 Bytes
/
104.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
*Name:Little shop of flowers
*LANG:C++
*Source:sgu104
*/
#include <cstdio>
#include <cstring>
#define INF -0x7FFFFFFF/2
using namespace std;
int a[200][200],ff[200][200];
int f,v,max=INF;
void print(int x,int y){
if (x>0){
int i=x;
while (ff[x][i]!=y) ++i;
print(x-1,y-a[x][i]);
printf("%d",i);
if (x!=f) printf(" ");
else printf("\n");
}
}
int main(){
scanf("%d %d",&f,&v);
for (int i=1;i<=f;++i)
for (int j=1;j<=v;++j)
scanf("%d",&a[i][j]);
for (int i=0;i<=110;++i)
for (int j=0;j<=110;++j)
ff[i][j]=INF;
for (int i=0;i<=v;++i) ff[0][i]=0;
for (int i=1;i<=f;++i)
for (int j=i;j<=v;++j)
for (int k=0;k<j;++k)
if (ff[i-1][k]+a[i][j]>ff[i][j])
ff[i][j]=ff[i-1][k]+a[i][j];
for (int i=1;i<=v;++i)
if (max<ff[f][i]) max=ff[f][i];
printf("%d\n",max);
print(f,max);
return 0;
}