题解 |
算力比赛
https://ac.nowcoder.com/acm/contest/53642/H
dp
#include <bits/stdc++.h>
typedef long long ll;
const ll maxn=105;
using namespace std;
ll val[maxn][maxn];
ll dp[maxn];
ll n,m;
int main(){
ll i,j,k;
cin>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%lld",&val[i][j]);
for(i=1;i<=n;i++)
{
for(j=m;j>=1;j--)
{
for(k=j;k>=1;k--)
{
if(dp[j]<dp[j-k]+val[i][k])
{
dp[j]=dp[j-k]+val[i][k];
}
}
}
}
printf("%lld\n",dp[m]);
}