P1231: [Usaco2008 Nov]mixup2 混乱的奶牛

这是一道状压DP,首先这道题让我意识到状态是从 1 to (1<<n)-1 的,所以当前加入的某头牛编号是从 0 to n-1 的,所以存储的时候习惯要改一下,这样子做状压DP才会顺一点吧。

PS:一定要仔细看题目,题目提醒了不会超过64位,然而悲催的没看见,于是第一次就WA了=-=//。

 1 const maxn=1<<16;
 2 var n,i,j,k,max:longint;
 3 ans:int64;
 4 s:array[0..16] of longint;
 5 f:array[0..16,0..maxn] of int64;
 6 begin
 7   readln(n,max);
 8   dec(n);
 9   for i:=0 to n do readln(s[i]);
10   for i:=0 to n do f[i,1<<i]:=1;
11   for i:=0 to 1<<(n+1)-1 do
12     for j:=0 to n do
13       if (i and (1<<j))>0 then
14         for k:=0 to n do
15           if (i and (1<<k)=0) and (abs(s[j]-s[k])>max) then
16             inc(f[k,i or (1<<k)],f[j,i]);
17   for i:=0 to n do
18     inc(ans,f[i,1<<(n+1)-1]);
19   writeln(ans);
20 end.
View Code

(转载请注明出处:http://www.cnblogs.com/Kalenda/)

转载于:https://www.cnblogs.com/Kalenda/p/4823215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值