本文主要是介绍UVA 10417 Gift Exchanging,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:对于概率很无解,参考:点击打开链接#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;double p[20][20];
int num[10];
int N;
double ans;void dfs(int cur,double cp){if (cur == N){ans += cp;return;}for (int i = 0; i < 5; i++){if (num[i] == 0)continue;if (p[cur][i] == 0.0)continue;num[i]--;dfs(cur+1,cp*p[cur][i]);num[i]++;}
}int main(){int t;scanf("%d",&t);while (t--){scanf("%d",&N);for (int i = 0; i < 5; i++)scanf("%d",&num[i]);for (int i = 0; i < N; i++)for (int j = 0; j < 5; j++)scanf("%lf",&p[i][j]);double Max = 0.0;int id;double sum = 0.0;for (int i = 0; i < 5; i++){if (num[i] == 0)continue;num[i]--;ans = 0.0;dfs(1,1.0);ans *= p[0][i];sum += ans;num[i]++;if (Max < ans/num[i]){Max = ans/num[i];id = i;}}printf("%d %.3lf\n",id+1,Max/sum);}return 0;
}
这篇关于UVA 10417 Gift Exchanging的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!