首页 > 其他分享 >P1896 [SCOI2005] 互不侵犯

P1896 [SCOI2005] 互不侵犯

时间:2022-10-27 20:48:19浏览次数:61  
标签:return 互不侵犯 int ll P1896 SCOI2005 false include

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
int n , k ;
ll f [ 10 ] [ ( 1 << 9 ) ] [ 90 ];
int num [ ( 1 << 9 ) ] ;
int vis [ ( 1 << 9 ) ] ;
void init (  )
{
    for ( int i = 0 ; i <= ( 1 << n ) - 1  ; i ++ )
    {
        vis [ i ] = 1 ;
        if ( ( ( i << 1 ) & i ) ) vis [ i ] = 0 ;
        if ( ( ( i >> 1 ) & i ) ) vis [ i ] = 0 ;
        for ( int j = 0 ; j < n ; j ++ )
        {
            if ( ( ( i >> j ) & 1 ) == 1 )
                num [ i ] ++ ;
        }
    }
    return ;
}
bool check ( int x , int y )
{
    if ( ( x & y ) > 0 ) return false;
    if ( ( x & ( y << 1 ) ) > 0 ) return false;
    if ( ( x & ( y >> 1 ) ) > 0 ) return false;
    return true;
}
ll ans = 0 ;
int main ( )
{
    cin >> n >> k ;
    init (  ) ;
    f [ 0 ] [ 0 ] [ 0 ] = 1 ;
    for ( int i = 1 ; i <= n ; i ++ ) // 这一行
    {
        for ( int j = 0 ; j <= ( 1 << n ) - 1 ; j ++ )
        {
            if ( vis [ j ] )
            for ( int l = num [ j ] ; l <= k ; l ++ )

            for ( int k = 0 ; k <= ( 1 << n ) - 1 ; k ++ )
            {
                if ( vis [ k ] && check ( j , k ) )
                {
                    f [ i ] [ j ] [ l ] += f [ i - 1 ] [ k ] [ l - num [ j ] ] ;
                }
            }
        }
    }
    for ( int i = 0 ; i <= ( 1 << n ) - 1 ; i ++ )
        ans += f [ n ] [ i ] [ k ] ;
    cout << ans ;
    return 0 ;
}

标签:return,互不侵犯,int,ll,P1896,SCOI2005,false,include
From: https://www.cnblogs.com/dadidididi/p/16833648.html

相关文章

  • BZOJ 1084([SCOI2005]最大子矩阵-长矩阵Dp)
    1084:[SCOI2005]最大子矩阵TimeLimit: 10Sec  MemoryLimit: 162MBSubmit: 586  Solved: 275[​​Submit​​][​​Status​​][​​Discuss​​]De......
  • [SCOI2005] 骑士精神 题解
    题目描述解法采用IDA*算法。不移动骑士而移动空格。每次限制深度,然后对每个遍历到的点进行一次估价,估价函数的值即为当前状态和终点的差异数。如果估计的加上已经确......
  • NC20240 [SCOI2005]互不侵犯
    题目原题地址:[SCOI2005]互不侵犯题目编号:NC20240题目类型:DP、状压DP时间限制:C/C++1秒,其他语言2秒空间限制:C/C++262144K,其他语言524288K1.题目大意在N×N的棋盘......
  • NC20240 [SCOI2005]互不侵犯KING
    题目链接题目题目描述在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案。国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格......
  • 1041 [SCOI2005]繁忙的都市 kruskal 最小生成树
     链接:https://ac.nowcoder.com/acm/contest/26077/1041来源:牛客网题目描述城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决......