其实这题可以搜索过的
by hgzx__lc @ 2023-09-04 16:09:42
```c
#include<iostream>
#include<cmath>
#define N 20
using namespace std;
int fit[N][N];
int m,n,maxn=0,x;
struct com{
int o,num;
};
com order[N],ans[N];
int profit=0;
void dfs(int,int);
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>fit[i][j];
dfs(m,1);
cout<<maxn<<endl;
for(int i=1;i<=x-1;i++)
cout<<ans[i].o<<" "<<ans[i].num<<endl;
}
void dfs(int s,int step)
{
if(s<0||step>n){
if(maxn<profit)
{
x=step;
maxn=profit;
for(int i=1;i<=step;i++)
{
ans[i].o=order[i].o;
ans[i].num=order[i].num;
}
}
return;
}
for(int j=0;j<=s;j++)
{
s-=j;
profit+=fit[step][j];
order[step].o=step;
order[step].num=j;
dfs(s,step+1);
s+=j;
profit-=fit[step][j];
}
return;
}
```
by hgzx__lc @ 2023-09-04 16:11:10