POJ-3071 Football 概率DP
2013-08-12 19:52
375 查看
题目链接:http://poj.org/problem?id=3071
题意:有2^n只足球队打比赛,编号1和2,3和4等进行淘汰制,胜利的进入下一轮接着淘汰,求最后哪支球队赢的概率最大。
简单题概率DP,画一颗树就知道方程了,f[i][j]表示第 i 轮第 j 只球队获胜的概率,则f[i][j]=Σ( f[i-1][k] ),k为第 j 只球队能遇见的所有球队。
题意:有2^n只足球队打比赛,编号1和2,3和4等进行淘汰制,胜利的进入下一轮接着淘汰,求最后哪支球队赢的概率最大。
简单题概率DP,画一颗树就知道方程了,f[i][j]表示第 i 轮第 j 只球队获胜的概率,则f[i][j]=Σ( f[i-1][k] ),k为第 j 只球队能遇见的所有球队。
//STATUS:C++_AC_94MS_320KB #include <functional> #include <algorithm> #include <iostream> //#include <ext/rope> #include <fstream> #include <sstream> #include <iomanip> #include <numeric> #include <cstring> #include <cassert> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; //#pragma comment(linker,"/STACK:102400000,102400000") //using namespace __gnu_cxx; //define #define pii pair<int,int> #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define PI acos(-1.0) //typedef typedef __int64 LL; typedef unsigned __int64 ULL; //const const int N=130; const int INF=0x3f3f3f3f; const LL MOD=1000000007,STA=8000010; const LL LNF=1LL<<55; const double EPS=1e-9; const double OO=1e30; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; //Daily Use ... inline int sign(double x){return (x>EPS)-(x<-EPS);} template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;} template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;} template<class T> inline T lcm(T a,T b,T d){return a/d*b;} template<class T> inline T Min(T a,T b){return a<b?a:b;} template<class T> inline T Max(T a,T b){return a>b?a:b;} template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);} template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);} template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} //End double f[8] ,p ; int n; void dfs(int l,int r,int d) { if(l==r){f[d][l]=1;return;} int i,j,mid=(l+r)>>1; dfs(l,mid,d+1); dfs(mid+1,r,d+1); for(i=l;i<=mid;i++){ f[d][i]=0; for(j=mid+1;j<=r;j++){ f[d][i]+=f[d+1][i]*f[d+1][j]*p[i][j]; } } for(i=mid+1;i<=r;i++){ f[d][i]=0; for(j=l;j<=mid;j++){ f[d][i]+=f[d+1][i]*f[d+1][j]*p[i][j]; } } } int main(){ // freopen("in.txt","r",stdin); int i,j,k,tot; while(~scanf("%d",&n) && n!=-1) { tot=1<<n; for(i=0;i<tot;i++){ for(j=0;j<tot;j++) scanf("%lf",&p[i][j]); } dfs(0,tot-1,0); double hig=0; int w; for(i=0;i<tot;i++){ if(f[0][i]>hig){hig=f[0][i],w=i+1;} } printf("%d\n",w); } return 0; }
相关文章推荐
- POJ 3071 Football(概率DP)
- POJ 3071 Football 概率DP 二进制优化
- poj-3071 Football 【概率dp,位运算】
- POJ-3071 Football (概率dp)
- POJ 3071 Football 概率DP
- POJ 3071 Football (概率DP)
- poj 3071 Football (概率DP水题)
- POJ 3071 Football 【概率DP】
- POJ 3071 - Football(概率DP 求概率)
- POJ 3071 Football(概率DP)
- POJ 3071 Football 概率DP入门
- Poj 3071 Football (比赛对阵 概率DP)
- poj 3071 Football(概率dp)
- [ACM] POJ 3071 Football (概率DP)
- poj 3071 Football(概率dp)
- POJ 3071 Football—概率DP-conquer sea博客
- POJ 3071 Football (概率DP)
- POJ 3071 Football(概率DP)
- [概率dp] poj 3071 Football
- POJ 3071 Football (概率DP)