怎么转移是个重点。
小清新题。-BY POPOQQQ
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,f[105][66666],d[105],c[105][20]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { scanf("%d",&d[i]); for (int j=1;j<=m;j++) scanf("%d",&c[i][j]); } memset(f,0x3f,sizeof(f)); f[0][0]=0; for (int i=1;i<=n;i++) { f[i][0]=0; for (int j=1;j<(1<<m);j++) for (int k=1;k<=m;k++) if ((1<<(k-1))&j) f[i][j]=min(f[i][j],min(f[i][j^(1<<(k-1))],f[i-1][j^(1<<(k-1))])+c[i][k]); for (int j=1;j<(1<<m);j++) { f[i][j]+=d[i]; f[i][j]=min(f[i][j],f[i-1][j]); } } printf("%d\n",f[n][(1<<m)-1]); return 0; }