Educational Codeforces Round 13 E. Another Sith Tournament 状态压缩dp
来源:互联网 发布:关于恋爱的软件 编辑:程序博客网 时间:2024/05/08 18:41
#include <cstdio>
#include <algorithm>
using namespace std;
const double EPS=1e-8;
int n;
double A[18][18], dp[(1<<18)+5][18];
bool vis[(1<<18)+5][18];
double solve(int mask, int cur) {
if (vis[mask][cur])
return dp[mask][cur];
for (int i=0; i<n; i++) {
if ((mask&(1<<i)))
dp[mask][cur]=max(dp[mask][cur],
solve(mask^(1<<i), cur)*A[cur][i]
+solve(mask^(1<<i), i)*A[i][cur]);
}
vis[mask][cur]=true;
return dp[mask][cur];
}
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
scanf("%lf", &A[i][j]);
double res=0;
dp[0][0]=1;
for (int i=0; i<n; i++)
res=max(res, solve(((1<<n)-1)^(1<<i), i));
printf("%lf\n", res);
return 0;
}
#include <algorithm>
using namespace std;
const double EPS=1e-8;
int n;
double A[18][18], dp[(1<<18)+5][18];
bool vis[(1<<18)+5][18];
double solve(int mask, int cur) {
if (vis[mask][cur])
return dp[mask][cur];
for (int i=0; i<n; i++) {
if ((mask&(1<<i)))
dp[mask][cur]=max(dp[mask][cur],
solve(mask^(1<<i), cur)*A[cur][i]
+solve(mask^(1<<i), i)*A[i][cur]);
}
vis[mask][cur]=true;
return dp[mask][cur];
}
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
scanf("%lf", &A[i][j]);
double res=0;
dp[0][0]=1;
for (int i=0; i<n; i++)
res=max(res, solve(((1<<n)-1)^(1<<i), i));
printf("%lf\n", res);
return 0;
}
0 0
- Educational Codeforces Round 13 E. Another Sith Tournament 状态压缩dp
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
- Educational Codeforces Round 13 E. Another Sith Tournament
- Codeforces 678E Another Sith Tournament(状压dp,概率dp)
- Codeforces 678E Another Sith Tournament(状压dp)
- Codeforces 678E(Another Sith Tournament)
- 【Codeforces 678E】Another Sith Tournament &【JZOJ 4648】锦标赛
- cf 678E Another Sith Tournament
- Educational Codeforces Round 13 E 状压dp
- cf678E. Another Sith Tournament
- Another Sith Tournament
- CF678E Another Sith Tournament(概率dp+状压dp)
- 【Codeforces 696B】Another Sith Tournament &【JZOJ 4647】寻找
- codeforces Educational Codeforces Round 16-E(DP)
- [CF678E] Another Sith Tournament([JZOJ4648] 锦标赛)
- Educational Codeforces Round 1 E.Chocolate Bar(DP)
- Educational Codeforces Round 2 E.Lomsat gelral(树形dp)
- Educational Codeforces Round 1 E Chocolate Bar(dp)
- iOS 应用版本号设置规则
- CI框架中控制器和控制器内的方法命名
- Java的随机验证码生成类
- Java文件操作类
- fragment 和 activity中的startActivityforResult
- Educational Codeforces Round 13 E. Another Sith Tournament 状态压缩dp
- Android中的一些第三方框架
- 苹果专利
- ios开发所需图片尺寸汇总
- *leetcode #128 in cpp
- JavaSE入门学习51:多线程编程(二)
- BASH中关于变量内替换详解
- git flow
- memcached 失效的数据去了哪里了