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

24 28 3

 Sample Output

416

 Source

FOJ有奖月赛-2015年10月

这题可以用dp做,费了不少时间。。我们可以预处理出答案,枚举第一个与第二个的情况,然后设dp[i][j][k]表示当前循环到i,已经选了j个,最后两位的状态为k所对应的二进制状态,k=0,1,2,3,0表示当前这个和前面一个都没取,1表示当前这个没取,前面取了。

然后i就可以从3开始转移了,这里要注意,dp[2][1]的方案数要看做0。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 0x7fffffff
#define maxn 1006
ll rear[maxn][maxn];
ll dp[maxn][maxn][4];
#define MOD 1000000007LL void init()
{
int i,j,ii,jj,a;
memset(rear,0,sizeof(rear));
for(ii=0;ii<2;ii++){
for(jj=0;jj<2;jj++){
memset(dp,0,sizeof(dp));
dp[2][0][ii+jj*2]=1;
for(i=3;i<=1002;i++){
for(j=0;j<=i;j++){
for(a=0;a<4;a++){
if(a%2==0){
dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][a])%MOD;
}
if(a==0 && j){
dp[i][j][1]=(dp[i][j][1]+dp[i-1][j-1][a])%MOD;
}
if(a%2==1){
dp[i][j][2]=(dp[i][j][2]+dp[i-1][j][a])%MOD;
}
if(a==1 && j){
dp[i][j][3]=(dp[i][j][3]+dp[i-1][j-1][a])%MOD;
} }
for(a=0;a<4;a++){
if( (a^(ii+jj*2))==0){
rear[i-2][j]=(rear[i-2][j]+dp[i][j][a])%MOD;
} } } } }
}
} int main()
{
init();
ll t;
scanf("%I64d",&t);
while(t--)
{
ll n,kk;
scanf("%I64d%I64d",&n,&kk);
int ans=0;
printf("%I64d\n",rear[n][kk]%MOD);
}
return 0;
}

fzu2200 cleaning的更多相关文章

  1. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

  2. Coursera-Getting and Cleaning Data-week1-课程笔记

    博客总目录,记录学习R与数据分析的一切:http://www.cnblogs.com/weibaar/p/4507801.html -- Sunday, January 11, 2015 课程概述 G ...

  3. Coursera-Getting and Cleaning Data-Week2-课程笔记

    Coursera-Getting and Cleaning Data-Week2 Saturday, January 17, 2015 课程概述 week2主要是介绍从各个来源读取数据.包括MySql ...

  4. Coursera-Getting and Cleaning Data-Week3-dplyr+tidyr+lubridate的组合拳

    Coursera-Getting and Cleaning Data-Week3 Wednesday, February 04, 2015 好久不写笔记了,年底略忙.. Getting and Cle ...

  5. Coursera-Getting and Cleaning Data-week4-R语言中的正则表达式以及文本处理

    博客总目录:http://www.cnblogs.com/weibaar/p/4507801.html Thursday, January 29, 2015 补上第四周笔记,以及本次课程总结. 第四周 ...

  6. 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划

    [BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...

  7. poj 2376 Cleaning Shifts

    http://poj.org/problem?id=2376 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  8. POJ 2376 Cleaning Shifts(轮班打扫)

    POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Farmer ...

  9. POJ 2376 Cleaning Shifts 贪心

    Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...

随机推荐

  1. Lambda表达式你会用吗?

    函数式编程 在正式学习Lambda之前,我们先来了解一下什么是函数式编程 我们先看看什么是函数.函数是一种最基本的任务,一个大型程序就是一个顶层函数调用若干底层函数,这些被调用的函数又可以调用其他函数 ...

  2. 【Jboss】应用中缺少宋体怎么办

    环境jboss4.2.2 系统CentOS7.2 1.新搭建的环境,但是没有字符集,在windows上的电脑上复制了一份宋体,打成zip包 将zip包上传到服务器中,解压 2.在/usr/share/ ...

  3. WeihanLi.Npoi 1.14.0 Release Notes

    WeihanLi.Npoi 1.14.0 Release Notes Intro 周末更新了一下项目,开始使用可空引用类型,并且移除了 net45 的支持,仅支持 netstandard2.0 Cha ...

  4. VBA调用数独求解器

    我开发了一个用于求解数独的dll文件,只需要双击一下注册表文件,就可以在VBA中调用这个功能了.具体步骤如下: 下载:https://share.weiyun.com/5dpcNqx 找到ExcelS ...

  5. 打包遇到错误Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

    引自:https://blog.csdn.net/xiexiangyan/article/details/107936774 遇到的问题 有一个maven项目,我clone一下最新的代码.准备打包(m ...

  6. 处理 K8S Orphaned pod found - but volume paths are still present on disk 孤儿pod

    问题概述 查看kubelet或/var/log/messages日志一直包错,发现是孤儿pod,是由于其pod被删除后存储路径还保存在磁盘. 报错如下 [root@node5 ~]# journalc ...

  7. uniapp根据登录用户的角色动态的改变tabBar的数量和内容

    此文章借鉴于https://blog.csdn.net/fuyuumiai/article/details/109746357,在此基础上修改小部分内容,适用于我这种uniapp小白 介绍: 现在我们 ...

  8. By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds.

    WebSocket proxying https://nginx.org/en/docs/http/websocket.html By default, the connection will be ...

  9. Google performance Tools (gperftools) 使用心得

    Google performance Tools (gperftools) 使用心得 gperftools是google开发的一款非常实用的工具集,主要包括:性能优异的malloc free内存分配器 ...

  10. php中两个函数可能导致的sql注入

    sprintf https://www.php.net/manual/zh/function.sprintf.php 漏洞demo: <?php $name = addslashes($_GET ...