UESTC 1851 Kings on a Chessboard

本文介绍了一个使用状态压缩动态规划(状压DP)解决的国际象棋问题:如何计算将k个相同的国王放置在一个x*y大小的棋盘上,使得任意两个国王都不互相攻击的有效方案数。考虑到方案数量可能很大,最终结果需要对1,000,000,007取模。
状压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 Da ta Structures     Basic Da ta 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                   

UESTC 1851 Kings on a Chessboard - qhn999 - 码代码的猿猿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 )

一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值