状压DP。。。

Kings on a Chessboard

Time Limit: 10000ms
Memory Limit: 65535KB
This problem will be judged on UESTC. Original ID: 1851
64-bit integer IO format: %lld      Java class name: Main
Font Size: + -
Type:  None Graph Theory     2-SAT     Articulation/Bridge/Biconnected Component     Cycles/Topological Sorting/Strongly Connected Component     Shortest Path         Bellman Ford         Dijkstra/Floyd Warshall     Euler Trail/Circuit     Heavy-Light Decomposition     Minimum Spanning Tree     Stable Marriage Problem     Trees     Directed Minimum Spanning Tree     Flow/Matching         Graph Matching             Bipartite Matching             Hopcroft–Karp Bipartite Matching             Weighted Bipartite Matching/Hungarian Algorithm         Flow             Max Flow/Min Cut             Min Cost Max Flow DFS-like     Backtracking with Pruning/Branch and Bound     Basic Recursion     IDA* Search     Parsing/Grammar     Breadth First Search/Depth First Search     Advanced Search Techniques         Binary Search/Bisection         Ternary Search Geometry     Basic Geometry     Computational Geometry     Convex Hull     Pick's Theorem Game Theory     Green Hackenbush/Colon Principle/Fusion Principle     Nim     Sprague-Grundy Number Matrix     Gaussian Elimination     Matrix Exponentiation Data Structures     Basic Data Structures     Binary Indexed Tree     Binary Search Tree     Hashing     Orthogonal Range Search     Range Minimum Query/Lowest Common Ancestor     Segment Tree/Interval Tree     Trie Tree     Sorting     Disjoint Set String     Aho Corasick     Knuth-Morris-Pratt     Suffix Array/Suffix Tree Math     Basic Math     Big Integer Arithmetic     Number Theory         Chinese Remainder Theorem         Extended Euclid         Inclusion/Exclusion         Modular Arithmetic     Combinatorics         Group Theory/Burnside's lemma         Counting     Probability/Expected Value Others     Tricky     Hardest     Unusual     Brute Force     Implementation     Constructive Algorithms     Two Pointer     Bitmask     Beginner     Discrete Logarithm/Shank's Baby-step Giant-step Algorithm     Greedy     Divide and Conquer Dynamic Programming                   Tag it!

You are given a chessboard of size x * y and k identical kings, and are asked to place all the kings on the board such that no two kings can attack each other. Two kings can attack each other if they are horizontally, vertically or diagonally adjacent.
Write a computer program that calculates the number of possible arrangements of the k kings on the given chessboard. Since the number of feasible arrangements may be large, reduce the number modulo 1,000,000,007.

Input

The first line of the input consists of a single integer T, the number of test cases. Each of the following T lines consists of three integers x; y and k,separated by one space.

0 < T <= 50
2 <= x; y <= 15
1 <= k <= x*y

Output

For each test case, output the number of possibilities modulo 1,000,000,007.

Sample Input

4
8 8 1
7 7 16
7 7 7
3 7 15

Sample Output

64
1
2484382
0

Source

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MOD=1000000007;

inline bool legal(int x,int y) {return x&y;}
long long int dp[16][1600][250];
int r,c,nums,state[1600],people[1600],kth;

bool isOK(int xia,int shang)
{
    int x=state[xia],y=state[shang];
    if(legal(x,y)) return false;
    if(legal(x<<1,y)||legal(x>>1,y)) return false;
    return true;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        scanf("%d%d%d",&r,&c,&kth);
        if(kth>(r+1)/2*(c+1)/2)
        {
            puts("0");
            continue;
        }
        if(c>r) swap(r,c);
        ///zuangtai
        nums=0;
        memset(state,0,sizeof(state));
        memset(people,0,sizeof(people));
        for(int i=0;i<(1<<c);i++)
        {
            if(legal(i,i<<1)||legal(i,i>>1)) continue;
            state[nums]=i;
            int k=i;
            while(k)
            {
                if(k&1) people[nums]++;
                k=k>>1;
            }
            nums++;
        }
        ///the firstline
        for(int i=0;i<nums;i++)
        {
            dp[1][people]=1;
        }
        for(int i=2;i<=r;i++)
        {
            for(int j=0;j<nums;j++)
            {
                for(int k=0;k<nums;k++)
                {
                    if(!isOK(j,k)) continue;
                    for(int l=people[k];l<250;l++)
                    {
                        if(l+people[j]<250)
                            dp[j][l+people[j]]=(dp[j][l+people[j]]+dp[i-1][k][l])%MOD;
                    }
                }
            }
        }
        long long int ans=0;
        for(int j=0;j<nums;j++)
        {
            ans=(ans+dp[j][kth])%MOD;
        }
        printf("%lld\n",ans%MOD);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

UESTC 1851 Kings on a Chessboard的更多相关文章

  1. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  2. CodeForces445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. ACM:UESTC - 649 括号配对问题 - stack

      UESTC - 649  括号配对问题 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu ...

  4. UESTC 1015 Lweb and pepper --前,后缀最值

    题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...

  5. FJOI省队集训 chessboard

    (题目懒得打字了,建议到新窗口查看) 显然这玩意儿是可以按位搞的...然后就是一个裸的最小割模型? 然而这样做理论上只有30分实际上有40分. 事实上我们可以发现,每一列的取值只和上一列有关,这样我们 ...

  6. [poj2446]Chessboard

    Description 给定一个m×n的棋盘,上面有k个洞,求是否能在不重复覆盖且不覆盖到洞的情况下,用2×1的卡片完全覆盖棋盘. Input 第一行有三个整数n,m,k(0<m,n<=3 ...

  7. POJ2699 The Maximum Number of Strong Kings

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2102   Accepted: 975 Description A tour ...

  8. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

  9. UVa12633 Super Rooks on Chessboard(容斥 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...

随机推荐

  1. Jquery 随便写些知识点

    针对jQuery随便写些觉得还挺实用的一些东西,也没系统的去理一番,只是想到哪写到哪,写的不完全也请多见谅. jQuery和其他javascript库产生$符号冲突了?$符号想必用jQuery的人都不 ...

  2. Sublime Text以及Package Control安装方法

    官方下载:Sublime Text 中国论坛:Sublime 论坛 Sublime Text 是一个代码编辑器,具有漂亮的用户界面和强大的功能,并且它还是一个跨平台的编辑器,同时支持Windows.L ...

  3. Visual Studio原生开发的10个调试技巧

    这篇文章只介绍了一些有关Visual Studio的基本调试技巧,但是还有其他一些同样有用的技巧.我整理了一些Visual Studio(至少在VS 2008下)原生开发的调试技巧.(如果你是工作在托 ...

  4. JavaScript函数之美~

    JavaScript函数之美~ 这篇文章,我将就以下几个方面来认识JavaScript中的函数. 函数为什么是对象,如何定义函数? 如何理解函数可以作为值被传递 函数的内部对象.方法以及属性 第一部分 ...

  5. python模块app登陆认证(M2Crypto数字证书加密)

    需求: 1.通过数字证书,非对称加密方式传送对称秘钥给服务端 2.用户名.密码使用对称秘钥加密,发送服务端验证 3.传送数据使用字节流方式 实现思路: 1.了解python的struct模块,用于字节 ...

  6. JS-事件之鼠标、键盘都能控制的下拉选框效果

    <script type="text/javascript"> window.onload=function(e){ var box=document.getEleme ...

  7. WinForm------TextEdit控件内容字体变*号

    "属性" -> “Properties” -> “LookAndFeel” -> “PasswordChar”

  8. Linux 的cp命令详解

    功能: 复制文件或目录说明: cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若同时指定多个文件或目录, ...

  9. linux命令:mkdir 命令详解

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...

  10. ubuntu下Eclipse安装

    安装的版本是MARS 直接复制安装包到安装的目录,然后tar zxvf XXXX 对于不能输入中文,把系统的输入法改成ibus就行了,fctix不支持eclipse 汉化包的下载地址 http://d ...