P4329 [COCI2006-2007#1] Bond
我们充分发扬人类智慧:事实上搜索可做。
首先暴力搜索显然是
首先我们假设深搜过程中每个搜索的是事件而不是人。
我们设
显然
这样速度快得飞起,不开 O2,最坏的点也就跑了
代码:
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
constexpr int N = 25;
double a[N][N], ans = 0;
int n;
double maxn[N], mulp[N];
bool st[25];
inline void dfs(register const int dep, register const double mul)
{
if (mul * mulp[dep] <= ans) return;
if (dep > n)
{
ans = mul;
return;
}
for (register int i(1); i <= n; i = -~i)
{
if (!st[i])
{
st[i] = 1;
dfs(dep + 1, mul * a[i][dep]);
st[i] = 0;
}
}
}
inline int read()
{
register char ch(getchar());
register int x(0);
while (ch < '0' || ch > '9')
{
ch = getchar();
}
while (ch >= '0' and ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x;
}
int main()
{
n = read();
for (register int i(1); i <= n; i = -~i)
{
for (register int j(1); j <= n; j = -~j)
{
a[i][j] = read() * 0.01;
maxn[j] = max(maxn[j], a[i][j]);
}
}
mulp[n + 1] = 1;
for (register int i(n); i >= 1; --i) mulp[i] = maxn[i] * mulp[i + 1];
dfs(1, 1);
printf("%.6lf\n", ans * 100);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现