Chess HDU
来源:互联网 发布:断开映射的网络驱动器 编辑:程序博客网 时间:2024/06/05 04:22
题目链接->Chess
車是中国象棋中的一种棋子,它能攻击同一行或同一列中没有其他棋子阻隔的棋子。一
天,小度在棋盘上摆起了许多車……他想知道,在一共N×M个点的矩形棋盘中摆最多个
数的車使其互不攻击的方案数。他经过思考,得出了答案。但他仍不满足,想增加一个
条件:对于任何一个車A,如果有其他一个車B在它的上方(車B行号小于車A),那么車A必须在車B的右边(車A列号大于車B)。
现在要问问你,满足要求的方案数是多少。
Input
第一行一个正整数T,表示数据组数。
对于每组数据:一行,两个正整数N和M(N<=1000,M<=1000)。
Output
对于每组数据输出一行,代表方案数模1000000007(1e9+7)。
解题报告
设ans[n][m]表示第n行第m列表示棋盘n,m的方案数。对于其中棋盘n,m他的方案数为棋盘(n-1,m-1)的方案数和棋盘(n,m-1)方案加起来的方案数。为棋盘(n,m)的方案数
1、if (n == m) ans[n][m] = 1;
2、if(n==1||m==1) ans[1][m] = ans[n][1] = 1;
3、当条件不满足 1和2时,答案为 ans[n][m] = ans[n-1][m-1]+ans[n][m-1];
代码
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int, int> P; // untility м╥нд╪Ч untility#define rep(i,x) for(int i = 0; i < x; i++)#define pu push#define pb push_back#define mp make_pair#define INF 0x3f3f3f3f#define fi first#define sc second//#define _Debugconst int MOD = 1e9+7;const int maxn = 1010;ll ans[maxn][maxn];int main(){ #ifdef _Debug freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif // _Debug for(int i = 1; i <= 1000; i++) ans[1][i] = i; for(int i = 2; i <= 1000; i++){ for(int j = i; j <= 1000; j++) if(i == j) ans[i][j] = 1; else ans[i][j] = (ans[i-1][j-1]+ans[i][j-1]) % MOD; } int kase; scanf("%d", &kase); while(kase--){ int n, m; scanf("%d%d", &n, &m); if(n > m) swap(n,m); printf("%LLd\n", ans[n][m]); } return 0;}
阅读全文
0 0
- Chess HDU
- Chess HDU
- Chess HDU
- HDU 3004 the chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 1691 Chinese Chess
- hdu 3345 War Chess
- HDU 3026 Chinese Chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu 4405 Aeroplane chess
- hdu 1680 Cheesy Chess
- HDU 4405 Aeroplane chess
- HDU 4405 Aeroplane chess
- 网易笔试编程第二题
- Android 音频输出方式监听
- 【MySQL】Explain
- RCNN学习笔记(9):SSD:Single Shot MultiBox Detector
- 练习题_3
- Chess HDU
- shell脚本学习使用for循环批量解压文件
- 基于Glide v4.x的图片加载进度监听
- 【github myLocker】线程返回值,重复引用头文件,二进制文件I/O
- python 错误枚举
- 练习题_4
- 爬虫下载淘宝html代码
- scala反转链表 leetcode 206 Reverse Linked List
- [整理]postgresql基本使用命令