P1896 [SCOI2005] 互不侵犯
  • $\mathscr{CODE}$

    #include<bits/stdc++.h>
    using namespace std;
    #define cint const unsigned&
    #define maxn 1005
    unsigned long long cnt,dp[10][maxn][82];
    unsigned n,K,sta[maxn],cnts[maxn];
    void dfs(cint x,cint num,cint cur){
        if(cur >= n){
            sta[++cnt] = x;
            cnts[cnt] = num;
            return;
        }
        dfs(x+(1<<cur),num+1,cur+2);
        dfs(x,num,cur+1);
    }
    inline bool nomatch(cint i,cint j){
        return (sta[i] & sta[j]) || (sta[i] & (sta[j]<<1)) || ((sta[i] << 1) & sta[j]); 
    }
    int main(){
        ios::sync_with_stdio(0),cin.tie(0);
        cin>>n>>K;
        dfs(0,0,0);
        for(unsigned i = 1;i<=cnt;++i){
            dp[1][i][cnts[i]] = 1;
        }
        for(unsigned char i = 2;i<=n;++i)
            for(unsigned j = 1;j<=cnt;++j)
                for(unsigned k = 1;k<=cnt;++k)
                    if(!nomatch(j,k))
                        for(unsigned l = cnts[j];l<=K;++l)
                            dp[i][j][l] += dp[i-1][k][l - cnts[j]];
        unsigned long long ans = 0;
        for(unsigned i = 1;i<=cnt;++i)
            ans += dp[n][i][K];
        cout<<ans;
    }
    //39ms
    
  • $\mathcal{Tip}$

    多重循环,注意变量冲突

    注意 long long

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇