状压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
Prev Submit Status Statistics Discuss Next
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

IDI Open 2013 Programming Contest
#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 )

转载于:https://www.cnblogs.com/CKboss/p/3350829.html

UESTC 1851 Kings on a Chessboard相关推荐

  1. UESTC 2015dp专题 E 菲波拉契数制 dp

    菲波拉契数制 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  2. The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554

    地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others)     M ...

  3. the 12th UESTC Programming Contest Final Justice is Given by Light (几何+ 二分)

    题目来源: http://acm.uestc.edu.cn/#/problem/show/814 题意:是给你一堆凸包上的点,这些点会形成一个凸多边形,有两个god站在这个多边形上,他们可以释放一个半 ...

  4. UESTC 电子科大专题训练 数据结构 J

    UESTC 1599 题意:中文题..不写了 思路:优先对列,小的优先 AC代码: #include "iostream" #include "string.h" ...

  5. ACM学习历程—UESTC 1226 Huatuo's Medicine(数学)(2015CCPC L)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. ...

  6. 2015 UESTC Winter Training #10【Northeastern Europe 2009】

    2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...

  7. 2015 UESTC 数据结构专题H题 秋实大哥打游戏 带权并查集

    秋实大哥打游戏 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...

  8. Numbers on the Chessboard

    You are given a chessboard of size n×nn×n. It is filled with numbers from 11 to n2n2 in the followin ...

  9. 2015 UESTC 数据结构专题G题 秋实大哥去打工 单调栈

    秋实大哥去打工 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...

最新文章

  1. OpenCV立体声匹配 stereo matching将L和R图像转换为视差和点云的实例(附完整代码)
  2. 几个功能强大的系统源码(机票分销、机票预订、OA、手机充值、wifi营销、网络超市、体检平台)...
  3. 盒子模型之边框border
  4. WordPress缓存插件WP-Super-Cache安装使用
  5. linux下定时执行sh
  6. 微信小程序直播分销商城源码
  7. 目标跟踪 MOSSE(Visual Object Tracking using Adaptive Correlation Filters)
  8. 高级信息系统项目管理师(高项)高分通过经验分享
  9. reverse-polish-notation
  10. JAVA面试题《下》
  11. 自己的第一个windows程序
  12. 不给别人添麻烦是一种教养还是性格缺陷?
  13. 红绿灯检测之模板匹配呸呸呸呸
  14. 单芯(多芯)液体不锈钢过滤器技术介绍
  15. 一个服务器部署一个以及两个以上tomcat时且为htts时教程
  16. 信号传输速率的快速了解
  17. 读《我不喜欢这世界,我只喜欢你》有感
  18. 中考计算机必背知识点,2019中考英语必背知识点汇总 常见考点总结
  19. 有什么好用的拍照翻译软件?拍照翻译软件哪个好用?
  20. python web项目导出zip文件_通过javascript在网页端生成zip压缩包并下载

热门文章

  1. 【Java】switch 是否能作用在 byte 上,是否能作用在 long 上,是否能作用在 String 上
  2. 11gR2 RAC GoldenGate的HA配置
  3. dbms_xplan.display_cursor 获取执行过的sql的执行计划
  4. [完美]原生JS获取浏览器版本判断--支持Edge,IE,Chrome,Firefox,Opera,Safari,以及各种使用Chrome和IE混合内核的浏览器...
  5. Vue学习笔记进阶篇——Render函数
  6. 坑爹的属性,android:descendantFocusability用法简析
  7. ODP.NET 10.2.0.20发布了
  8. 7-5 编程题:选修课成绩统计问题-hebust (12 分)
  9. linux 优化内存分配,Linux性能优化 第三章 性能工具:系统内存
  10. 求组合数的算法 java,求一个整数的组合数算法(java)