Description
每个人都知道詹姆斯邦德,著名的007,但很少有人知道很多任务都不是他亲自完成的,而是由他的堂弟们吉米邦德完成(他有很多堂弟),詹姆斯已经厌倦了把一个个任务分配给一个个吉米,他向你求助。
每个月,詹姆斯都会收到一些任务,根据他以前执行任务的经验,他计算出了每个吉米完成每个任务的成功率,要求每个任务必须分配给不同的人去完成,每个人只能完成一个任务。
请你编写程序找到一个分配方案使得所有任务都成功完成的概率。
Input
输入第一行包含一个整数N,表示吉米邦德的数量以及任务的数量(正好相等,1<=N<=20)。
接下来N行,每行包含N个0到100之间整数,第i行的第j个数Aij表示吉米邦德i完成任务j成功的概率为Aij%
Output
输出所有任务成功完成最大的概率,结果保留6位小数。
Sample Input
输入1:
2
100 100
50 50
输入2:
2
0 50
50 0
输入3:
3
25 60 100
13 0 50
12 70 90
Sample Output
输出1:
50.000000
输出2:
25.000000
输出3:
9.100000
经典的状态压缩dp,我居然没想出来,只是打了个有70分的暴力。
设f[I,j]为第i个人的在j状态的最优解。
我们有位运算转移即可。
const
maxn=1048575;
var
b:array[1..20] of longint;
f:array[0..maxn] of real;
s:array[0..20,0..20] of real;
a:array[1..20] of longint;
n,i,l,j,k,m,s1,t:longint;
function max(a,b:real):real;
begin
if a>b then max:=a
else max:=b;
end;
begin
readln(n);
fori:=1 to n do
forj:=1 to n do
read(s[i,j]);
b[1]:=1;
f[0]:=100;
fori:=2 to n do
b[i]:=b[i-1]*2;
fori:=1 to b[n] shl 1-1 do
begin
t:=0;
s1:=0;
for j:=1 to n do
if i and b[j]>0 then
begin
inc(s1);
a[s1]:=j;
inc(t);
end;
for j:=1 to s1 do
f[i]:=max(f[i-b[a[j]]]*s[a[j],t]/100,f[i]);
end;
write(f[b[n]shl 1-1]:0:6);
end.
const
maxn=1048575;
var
b:array[1..20] of longint;
f:array[0..maxn] of real;
s:array[0..20,0..20] of real;
a:array[1..20] of longint;
n,i,l,j,k,m,s1,t:longint;
function max(a,b:real):real;
begin
if a>b then max:=a
else max:=b;
end;
begin
readln(n);
fori:=1 to n do
forj:=1 to n do
read(s[i,j]);
b[1]:=1;
f[0]:=100;
fori:=2 to n do
b[i]:=b[i-1]*2;
fori:=1 to b[n] shl 1-1 do
begin
t:=0;
s1:=0;
for j:=1 to n do
if i and b[j]>0 then
begin
inc(s1);
a[s1]:=j;
inc(t);
end;
for j:=1 to s1 do
f[i]:=max(f[i-b[a[j]]]*s[a[j],t]/100,f[i]);
end;
write(f[b[n]shl 1-1]:0:6);
end.