Problem 2200 cleaning

 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

2
4 2
8 3

 Sample Output

4
16

 Source

FOJ有奖月赛-2015年10月

 
 
题解:
  设定 f[k][h] [i][j] 表示在不考虑环的清形下第一,二位置上的选择状态为k,h下,前i个选了j个人的方案数
    dp[k][h][i][j], 表示在考虑环的清形下第一,二位置上的选择状态为k,h下,前i个选了j个人的方案数
  那么对于f数组的递推,当前第i位置选与不选,i-1位置选与不选有
        f[k][h] = f[k][h][ii-1][j] +f[k][h][i-3][j-1] + f[k][h][i-4][j-2];
  对于dp数组转移同理就是拿f数组来更新
  具体看代码
#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的更多相关文章

  1. FZU Problem 2200 cleaning dp

    Problem Description N个人围成一圈在讨论大扫除的事情,需要选出K个人.但是每个人与他距离为2的人存在矛盾,所以这K个人中任意两个人的距离不能为2,他们想知道共有多少种方法. Inp ...

  2. ZOJ Problem Set - 3822Domination(DP)

    ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...

  3. fzuoj Problem 2129 子序列个数

    http://acm.fzu.edu.cn/problem.php?pid=2129 Problem 2129 子序列个数 Accept: 162    Submit: 491Time Limit: ...

  4. hdu4976 A simple greedy problem. (贪心+DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...

  5. fzuoj Problem 2179 chriswho

    http://acm.fzu.edu.cn/problem.php?pid=2179 Problem 2179 chriswho Accept: 57    Submit: 136 Time Limi ...

  6. fzuoj Problem 2177 ytaaa

    http://acm.fzu.edu.cn/problem.php?pid=2177 Problem 2177 ytaaa Accept: 113    Submit: 265Time Limit: ...

  7. 【HDU 5233】Tree chain problem (树形DP+树剖+线段树|树状数组)最大权不相交树链集

    [题目] Tree chain problem Problem Description Coco has a tree, whose vertices are conveniently labeled ...

  8. 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 ...

  9. D. Easy Problem(简单DP)

    题目链接:http://codeforces.com/contest/1096/problem/D 题目大意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在har ...

随机推荐

  1. struts2知识系统整理

    1.MVC 和 JSP Model 2 **   a.:M-Model 模型 包含两部分:业务数据和业务处理逻辑  b.V-View 视图:视图(View)的职责是负责显示界面和用户交互(收集用户信息 ...

  2. 【java基础 11】java集合框架学习

    导读:本篇博客主要是从整体上了解java的集合框架,然后主要介绍几个自己在项目中用到的结构,比如说:hashtable.hashmap.hashset.arraylist等! 一.宏观预览 从宏观上看 ...

  3. 解开Future的神秘面纱之任务执行

    此文承接之前的博文 解开Future的神秘面纱之取消任务 补充一些任务执行的一些细节,并从全局介绍程序的运行情况. 任务提交到执行的流程 前文我们已经了解到一些Future的实现细节,这里我们来梳理一 ...

  4. FreeMarker常用语法学习

    1.API网址 http://freemarker.sourceforge.net/docs/ 2.一个Table的例子 freemarker 对表格的控制 这里将所有需要在一个区域显示到数据全部ad ...

  5. Virtualization基础

    官方文档学习 https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/Virtualization_G ...

  6. 测试开发系列之Python开发mock接口(三)

    于进入主题了,前面的准备工作都已经做好了,下面就开始写逻辑的代码了,代码我已经写好了,每行都加了注释,不明白的可以留言.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...

  7. python实现显示安装进度条

    一直很好奇那种安装进度条,或者启动程序时候显示的进度条是怎么实现的,学习了python之后,sys模块中有个方法可以实现,代码如下:   1 2 3 4 5 6     import sys,time ...

  8. SELinux 服务检查与关闭

    查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态 SELinux status:         ...

  9. Unable to locate Attribute with the the given name [] on this ManagedType

    最近在写Springboot+hibernate的项目,遇到这个问题 好坑,查了半天没发现我哪里配置错了,后来发现实体类声明字段大小写敏感,把声明字段改成小写就行了

  10. NSTimer与NSRunLoop的关系分析

    NSTimer与NSRunLoop的关系分析 发表于 2013 年 6 月 27 日 由 bluev | 6 次浏览 最近关于NSTimer和NSRunLoop的关系,做了一个小试验.代码地址:htt ...