题解点我

Code

#include <bits/stdc++.h>

typedef long long LL;
typedef unsigned long long uLL; #define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define MP(x, y) std::make_pair(x, y)
#define DE(x) cerr << x << endl;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define GO cerr << "GO" << endl; using namespace std; inline void proc_status()
{
ifstream t("/proc/self/status");
cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}
inline int read()
{
register int x = 0; register int f = 1; register char c;
while (!isdigit(c = getchar())) if (c == '-') f = -1;
while (x = (x << 1) + (x << 3) + (c xor 48), isdigit(c = getchar()));
return x * f;
}
template<class T> inline void write(T x)
{
static char stk[30]; static int top = 0;
if (x < 0) { x = -x, putchar('-'); }
while (stk[++top] = x % 10 xor 48, x /= 10, x);
while (putchar(stk[top--]), top);
}
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } const int maxN = 1000;
const int mod = 1e9 + 7; void pls(int &x, int y)
{
x += y;
if (x >= mod) x -= mod;
if (x < 0) x += mod;
} int n, K, to[maxN], sum[maxN];
int dp[maxN][maxN], g[maxN]; int main()
{
#ifndef ONLINE_JUDGE
freopen("xhc.in", "r", stdin);
freopen("xhc.out", "w", stdout);
#endif
cin >> n >> K;
for (int i = 1; i <= K; ++i)
{
int u, v;
cin >> u >> v;
to[u] = v;
to[v] = u;
sum[u]++;
sum[v]++;
}
n <<= 1;
for (int i = 1; i <= n; ++i)
sum[i] += sum[i - 1];
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = 1ll * (i - 1) * g[i - 2] % mod;
for (int i = 1; i <= n; ++i)
{
for (int j = i + 1; j <= n; j += 2)
{
bool flag = 0;
for (int k = i; k <= j; ++k)
if (to[k] and (to[k] < i || to[k] > j))
{
flag = 1;
break;
}
if (flag)
continue;
dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
for (int l = i + 1; l < j; l += 2)
pls(dp[i][j], -1ll * dp[i][l] * g[j - l- sum[j] + sum[l]] % mod);
}
}
K <<= 1;
int ans(0);
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; j += 2)
pls(ans, 1ll * dp[i][j] * g[n - (j - i + 1) - (K - (sum[j] - sum[i - 1]))] % mod);
cout << ans << endl;
return 0;
}

[AGC028D](dp计数)的更多相关文章

  1. 动态规划(DP计数):HDU 5116 Everlasting L

    Matt loves letter L.A point set P is (a, b)-L if and only if there exists x, y satisfying:P = {(x, y ...

  2. 【POJ1952】逢低吸纳 dp+计数

    题目大意:给定一个有 N 个数的序列,求其最长下降子序列的长度,并求出有多少种不同的最长下降子序列.(子序列各项数值相同视为同一种) update at 2019.4.3 题解:求最长下降子序列本身并 ...

  3. Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)

    题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...

  4. HDU 4055 The King’s Ups and Downs(DP计数)

    题意: 国王的士兵有n个,每个人的身高都不同,国王要将他们排列,必须一高一矮间隔进行,即其中的一个人必须同时高于(或低于)左边和右边.问可能的排列数.例子有1千个,但是最多只算到20个士兵,并且20个 ...

  5. HDU 4055 Number String(DP计数)

    题意: 给你一个含n个字符的字符串,字符为'D'时表示小于号,字符为“I”时表示大于号,字符为“?”时表示大小于都可以.比如排列 {3, 1, 2, 7, 4, 6, 5} 表示为字符串 DIIDID ...

  6. 动态规划(DP计数):HDU 5117 Fluorescent

    Matt, a famous adventurer who once defeated a pack of dire wolves alone, found a lost court. Matt fi ...

  7. [HAOI2010]最长公共子序列(LCS+dp计数)

    字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x0,x1,…,xm-1”,序列Y=“y0,y1,…,yk-1”是X ...

  8. F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数

    F - Tmutarakan Exams 题意 : 从 < = S 的 数 中 选 出 K 个 不 同 的 数 并 且 gcd > 1 .求方案数. 思路 :记 录 一 下 每 个 数 的 ...

  9. hdu-6415 Rikka with Nash Equilibrium dp计数题

    http://acm.hdu.edu.cn/showproblem.php?pid=6415 题意:将1~n*m填入一个n*m矩阵 问只有一个顶点的构造方案. 顶点的定义是:某数同时是本行本列的最大值 ...

随机推荐

  1. bootstrap复习

    菜单 <div class="row">下拉菜单/分裂菜单</div> <div class="dropdown btn-group&quo ...

  2. 使用vue-resource请求数据的步骤

    1.需要安装 vue-resource模块 注意加上--save npm install vue-resource --save 2.main.js 引入vue-resource import Vue ...

  3. process-hacker

    https://github.com/processhacker/processhacker#process-hacker // begin_phapppub typedef enum _PH_KNO ...

  4. Promise.all 的原理

    // all的原理 Promise.all = function(values){ return new Promise((resolve,reject)=>{ let results = [] ...

  5. bzoj3991 [SDOI2015]寻宝游戏 树链的并

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3991 题解 貌似这个东西叫做树链的并,以前貌似写过一个类似的用来动态维护虚树. 大概就是最终的 ...

  6. 4412 使用usb摄像头拍照YUYV格式

    一.内核设置 Linux内核中已经带有很完善的USB摄像头驱动,支持几乎所有的USB摄像头,我们只需要配置内核,选择上相应的Sensor型号即可. 配置内核,支持USB摄像头: Device Driv ...

  7. 状态管理Vuex的使用总结

    1.Vuex.store 的基本使用 Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式,它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. Vu ...

  8. Nginx的启动、停止与重启---linux

    一.选定安装文件目录 可以选择任何目录 cd /usr/local/src 二.安装PCRE库 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcr ...

  9. Queue1循环队列

    循环队列 1 #include<iostream> using namespace std; //#define maxSize 20 template <class T> c ...

  10. PHP获取时间排除周六、周日的两个方法

    //方法一: <?php $now = time(); //指定日期用法 $now = strtotime('2014-01-08') ; $day = 3600*24; $total = 12 ...