原题链接
满分代码
#include#include #include #include using namespace std; typedef double LL; const int N = 1<<16,M = 6; int n,k; LL a[16]; LL f[N][16*6]; //记忆化搜索,期望, 状态和钱 bool g[N][16*6]; int get(int x){ int sum = 0; for (int i = 0; i < n; i ++ ){ if(!(x>>i&1)){ sum++; } } return sum; } LL dfs(int state,int money,int len){ //表示手中还没有的牌的数量 if(g[state][money]){ //说明这种情况已经计算过 return f[state][money]; } if(state==(1< =len*k){ //钱够买剩余全部了 return 0; } LL res=0; for (int i = 0; i < n; i ++ ){ int c = (state>>i)&1; if(!c){ //找手中还没有的牌 LL t = dfs(state|(1<1e-4){ cout << f[state][money] <<" "< > n >> k; for (int i = 0; i < n; i ++ ){ cin >>a[i]; } memset(g, 0, sizeof g); LL t = dfs(0,0,n); printf("%.10lf",t); }



