FZUOJ Problem 2200 cleaning DP
Problem Description
N个人围成一圈在讨论大扫除的事情,需要选出K个人。但是每个人与他距离为2的人存在矛盾,所以这K个人中任意两个人的距离不能为2,他们想知道共有多少种方法。
Input
第一行包含一个数T(T<=100),表示测试数据的个数。
接下来每行有两个数N,K,N表示人数,K表示需要的人数(1<=N<=1000,1<=K<=N)。
Output
输出满足题意的方案数,方案数很大,所以请输出方案数mod 1,000,000,007 后的结果。
Sample Input
4 2
8 3
Sample Output
16
Source
FOJ有奖月赛-2015年10月
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 1e3+, M = 1e6+, mod = 1e9+,inf = 2e9; void update(int x,int& y) {
y += x;
if(y > mod) y -= mod;
}
int T,dp[][][N][N],f[][][N][N];//前i个人选j人,前两人状态
void init() {
dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ; dp[][][][] = ; dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ; dp[][][][] = ;
dp[][][][] = ;
dp[][][][] = ; dp[][][][] = ; for(int i = ; i < ; ++i) {
for(int j = ; j < ; ++j) {
for(int k = ; k <= ; ++k) {
for(int h = ; h <= k; ++h)
f[i][j][k][h] = dp[i][j][k][h];
}
}
}
f[][][][] = ;
f[][][][] = ;
for(int k = ; k < ; ++k) {
for(int h = ; h < ; ++h) {
for(int i = ; i <= ; ++i) {
for(int j = ; j <= i; ++j) {
//不选, i-1选
if(i >= ) {
if(!k && j >= ) update(f[k][h][i-][j-],dp[k][h][i][j]);
if(!k && j >= )
if(i >= )update(f[k][h][i-][j-],dp[k][h][i][j]);
}
else {
if(!k && j >= ) update(f[k][h][i-][j-],dp[k][h][i][j]);
} //i不选,i-1不选
update(f[k][h][i-][j],dp[k][h][i][j]);
//i位置选,i-1不选
if(!h&&j>=)update(f[k][h][i-][j-],dp[k][h][i][j]); //i位置选,i-1选
if(!k&&!h&&j>=)
update(f[k][h][i-][j-],dp[k][h][i][j]); update(f[k][h][i-][j],f[k][h][i][j]);
if(i>=&&j>=)update(f[k][h][i-][j-],f[k][h][i][j]);
if(i>=&&j>=)update(f[k][h][i-][j-],f[k][h][i][j]);
}
}
}
}
}
int main() {
init();
scanf("%d",&T);
while(T--) {
int k,n;
scanf("%d%d",&n,&k);
int ans = ;
for(int i = ; i < ; ++i) {
for(int j = ; j < ; ++j) {
update(dp[i][j][n][k],ans);
}
}
printf("%d\n",ans);
}
return ;
}
FZUOJ Problem 2200 cleaning DP的更多相关文章
- FZU Problem 2200 cleaning dp
Problem Description N个人围成一圈在讨论大扫除的事情,需要选出K个人.但是每个人与他距离为2的人存在矛盾,所以这K个人中任意两个人的距离不能为2,他们想知道共有多少种方法. Inp ...
- ZOJ Problem Set - 3822Domination(DP)
ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...
- fzuoj Problem 2129 子序列个数
http://acm.fzu.edu.cn/problem.php?pid=2129 Problem 2129 子序列个数 Accept: 162 Submit: 491Time Limit: ...
- hdu4976 A simple greedy problem. (贪心+DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...
- fzuoj Problem 2179 chriswho
http://acm.fzu.edu.cn/problem.php?pid=2179 Problem 2179 chriswho Accept: 57 Submit: 136 Time Limi ...
- fzuoj Problem 2177 ytaaa
http://acm.fzu.edu.cn/problem.php?pid=2177 Problem 2177 ytaaa Accept: 113 Submit: 265Time Limit: ...
- 【HDU 5233】Tree chain problem (树形DP+树剖+线段树|树状数组)最大权不相交树链集
[题目] Tree chain problem Problem Description Coco has a tree, whose vertices are conveniently labeled ...
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp
Problem G. k-palindrome 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022 ...
- D. Easy Problem(简单DP)
题目链接:http://codeforces.com/contest/1096/problem/D 题目大意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在har ...
随机推荐
- .net提高文章
文章:.NET程序性能的基本要领 文章:你的字典里有多少元素? 文章:快速自检电脑是否被黑客入侵过(Windows版) 文章:关于DNS,你应该知道这些
- Linux 查看端口占用并杀掉进程
1. 查看端口号占用情况: netstat -apn|grep 11305 tcp 0 0 10.65.42.27:80 172.22.142.20: ...
- Count on a tree(bzoj 2588)
Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始 ...
- Lucene 6.5.0 入门Demo
Lucene 6.5.0 要求jdk 1.8 1.目录结构: 2.数据库环境: private int id; private String name; private float price; pr ...
- poj1149最大流经典构图神题
题意:n个顾客依次来买猪,有n个猪房,每个顾客每次可以开若干个房子,买完时,店主可以调整这位顾客 开的猪房里的猪,共m个猪房,每个猪房有若干猪,求最多能卖多少猪. 构图思想:顾客有先后,每个人想要的猪 ...
- git(三):第一次github了解使用
第一次使用github,看了一下使用说明,创建第一个repository,以后还要多学习. 一.Github创建一个新仓库 ······Creat a new repository 创建一个新仓库,点 ...
- 2716 [Violet 3] 天使玩偶
@(BZOJ)[CDQ分治] Sample Input 100 100 81 23 27 16 52 58 44 24 25 95 34 2 96 25 8 14 97 50 97 18 64 3 4 ...
- github/gitlab ssh-keys全局唯一
我们知道,通过在gitlab.github上设置ssh-key,可以直接拉取代码:git clone …… 公司为了代码安全,会对代码访问权限进行控制,不同人有不同代码的访问权限. 有时候,为了临时获 ...
- flask的debug模式下,网页输入pin码进行调试
网站后端Python+Flask .FLASK调试模式之开启DEBUG与PIN使用? 自动加载: # 方式一 1 2 if __name__ == '__main__': app.run(ho ...
- 几种自己主动运行js代码的方式
近期在看jquery,发现他竟然能自己主动运行js代码,于是就查了下.收集了几种经常使用的实现方法 jquery的方法 使用场景:不论什么须要运行的js特效 $(document).ready(fun ...