先打一个最裸的暴力再优化
10分代码
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define N 105
using namespace std;
int n,m,a[N][N],true_ans,choose[N]; //n束花 m个瓶子
vector <int> q;
void dfs(int now,int bottle,int ans,vector<int> v)
{
// cout<<now<<" "<<bottle<<" "<<ans<<en
if(now==n)
{
if(ans>true_ans)
{
true_ans=ans;
for(int i=0;i<n;i++)
{
choose[i]=v[i];
}
}
return;
}
for(int i=bottle+1;i<=m;i++)
{
v.push_back(i);
dfs(now+1,i,ans+a[now+1][i],v);
v.pop_back();
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{