#include<bits/stdc++.h>
using namespace std;
const int N = 20;
int n , m;
int a[12][N];
int f[12][N];
int maxn;
int q;
int write(int i , int j)
{
if(i == 0) return 0;
for(int s = 0;s <= j; ++ s)
{
if(maxn == f[i - 1][s] + a[i][i - s])
{
maxn = f[i - 1][s];
write(i - 1 , s);
q ++;
if(q == n) cout << i << " " << j - s;
else cout << i << " " << j - s << '\n';
break;
}
}
}
int main()
{
cin >> n >> m;
for(int i = 1;i <= n; ++ i)
for(int j = 1;j <= m; ++ j)
cin >> a[i][j];
for(int i = 1;i <= n; ++ i)
{
for(int j = 1;j <= m; ++ j)
{
maxn = 0;
for(int k = 0;k <= j; ++ k)
if(f[i - 1][k] + a[i][j - k] > maxn)
maxn = f[i - 1][k] + a[i][j - k];
f[i][j] = maxn;
}
}
cout << f[n][m] << '\n';
write(n , m);
return 0;
}
开O2全RE,不开O2全WA,but阳历过了
求大佬们帮助