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. nginx的详解(三)

    6.禁止访问某个文件或目录1)禁止访问以txt或doc结尾的文件location ~* \.(txt|doc)${root /data/www/wwwroot/linuxtone/test;deny ...

  2. shell的brake和continue的用法

    在循环过程中,有时候需要在未达到循环结束条件时强制跳出循环,像大多数编程语言一样,Shell也使用 break 和 continue 来跳出循环. break命令 break命令允许跳出所有循环(终止 ...

  3. 【Luogu】P3708Koishi的数字游戏(数论)

    题目链接 考虑f(i)=i%1+i%2+i%3+.....+i%n f(i+1)=(i+1)%1+(i+1)%2+......+(i+1)%n 其中不是i+1的因数的部分在f(i+1)的地方都加了1. ...

  4. 【Luogu】P1854花店橱窗布置(DP)

    照例良心题目链接 此题使用f[i][j]表示前i束花放进前j个花瓶的时候的最大值.转移方程如下 f[i][j]=max(f[i][j-1],f[i-1][j-1]+que[i][j]) 其中que[i ...

  5. POJ 2187 Beauty Contest ——计算几何

    貌似直接求出凸包之后$O(n^2)$暴力就可以了? #include <cstdio> #include <cstring> #include <string> # ...

  6. [luoguP2221] [HAOI2012]高速公路(线段树)

    传送门 考虑每一段对答案的贡献 用每一段的左端点来表示当前这一段,那么区间就变成了[1,n-1] 如果询问区间[l,r],其中一个点的位置为x,则它对答案的贡献为(x-l)*(r-x)*s[x](s[ ...

  7. [HDU-5536] Chip Factory (01字典树)

    Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...

  8. KS求有向图强连通分量模板

    #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; ; *maxn; struct no ...

  9. cf550D Regular Bridge

    Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...

  10. 洛谷 [P2964] 硬币的游戏

    博弈论+dp 依旧是博弈论的壳子,但问的是最大值,所以要dp 设 dp[i][j] 表示该取 i 号硬币,上一次取了 j 个的先手能取的最大值, 因为每次从小到大枚举复杂度太高,所以我们要从 dp[i ...