标签:ret ace 分析 题解 ++ https value space turn
maxx = max(ans[i - 1][k] + value[i][j - k],maxx);
a[i][j] = maxx;
---------------------------分析完毕--------------------------
#include <bits/stdc++.h>
using namespace std;
int a[50][50],ans[50][50],p[50],maxx;
inline int print(int i,int j){
if(i == 0)return 0;
for(int k = 0;k <= j;k++){
if(maxx == ans[i - 1][k] + a[i][j - k]){
maxx = ans[i - 1][k];
print(i - 1,k);
printf("%d %d\n",i,j - k);
break;
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
maxx = 0;
for(int k = 0;k <= j;k++){
maxx = max(ans[i - 1][k] + a[i][j - k],maxx);
ans[i][j] = maxx;
}
}
}
printf("%d\n",ans[n][m]);
print(n,m);
return 0;
}
标签:ret ace 分析 题解 ++ https value space turn
原文地址:https://www.cnblogs.com/czy--blog/p/11741841.html