状压dp求条!

B3624 猫粮规划

ChangeYuAN @ 2024-11-23 10:07:24

#include<bits/stdc++.h>
using namespace std;
const int MAXLEN=(1<<21)+1;
int dp[MAXLEN],n,l,r,ans=0,a[20];

signed main(){
    scanf("%d%d%d",&n,&l,&r);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=(1<<(n+1));i++){
        for(int j=1;j<=n;j++){
            if(i&(1<<j)){
                dp[i]+=a[j];
            }
        }if(dp[i]>=l&&dp[i]<=r) ans++;
    }printf("%d",ans>>1);
    return 0;
}

by ChangeYuAN @ 2024-11-23 10:09:15

厌氧50pts


by Rindong @ 2024-11-23 10:19:56

@ChangeYuAN n \le 40 你咋压


by ChangeYuAN @ 2024-11-23 10:21:12

@Rindong 偶,看错数据范围了


by ChangeYuAN @ 2024-11-23 10:24:19

绷不住了


|