「HAOI2011」Problem c

传送门

由于这道题本人讲得不好,可以参考这位dalao的博客

我可就直接上代码了。。。

参考代码:

/*--------------------------------
Code name: D.cpp
Author: The Ace Bee
This code is made by The Ace Bee
--------------------------------*/
#include <cstdio>
#include <cstring>
#define int long long
#define rg register
#define file(x) \
freopen(x".in", "r", stdin); \
freopen(x".out", "w", stdout);
const int $ = 333;
inline int read() {
int s = 0; bool f = false; char c = getchar();
while (c < '0' || c > '9') f |= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
return f ? -s : s;
}
int n, m, mod;
int c[$][$], cnt[$], sum[$], f[$][$];
inline void getc() {
c[0][0] = 1;
for (rg int i = 1; i <= n; ++i) {
c[i][0] = 1;
for (rg int j = 1; j <= i; ++j)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
}
inline void plus(int& a, int b) { a = (a + b) % mod; }
signed main() {
// file("D");
for (rg int T = read(); T; --T) {
memset(cnt, 0, sizeof cnt);
memset(f, 0, sizeof f);
n = read(), m = read(), mod = read();
getc();
for (rg int i = 1; i <= m; ++i) read(), ++cnt[read()];
sum[0] = n - m;
bool flag = true;
for (rg int i = 1; i <= n; ++i) {
sum[i] = 1ll * cnt[i] + 1ll * sum[i - 1];
if (sum[i] < i) { flag = false; break; }
}
if (!flag) { puts("NO"); continue; }
f[0][0] = 1;
for (rg int i = 1; i <= n; ++i)
for (rg int j = i; j <= sum[i]; ++j)
for (rg int k = cnt[i]; j - k >= i - 1; ++k)
plus(f[i][j], 1ll * f[i - 1][j - k] * c[sum[i - 1] - j + k][k - cnt[i]]);
printf("YES %lld\n", f[n][n]);
}
return 0;
}

「HAOI2011」Problem c的更多相关文章

  1. BZOJ2301/LG2522 「HAOI2011」Problem B 莫比乌斯反演 数论分块

    问题描述 BZOJ2301 LG2522 积性函数 若函数 \(f(x)\) 满足对于任意两个最大公约数为 \(1\) 的数 \(m,n\) ,有 \(f(mn)=f(m) \times f(n)\) ...

  2. loj#2483. 「CEOI2017」Building Bridges 斜率优化 cdq分治

    loj#2483. 「CEOI2017」Building Bridges 链接 https://loj.ac/problem/2483 思路 \[f[i]=f[j]+(h[i]-h[j])^2+(su ...

  3. loj2353. 「NOI2007」 货币兑换

    loj2353. 「NOI2007」 货币兑换 链接 https://loj.ac/problem/2353 思路 题目不重要,重要的是最后一句话 提示 输入文件可能很大,请采用快速的读入方式. 必然 ...

  4. LibreOJ 2003. 「SDOI2017」新生舞会 基础01分数规划 最大权匹配

    #2003. 「SDOI2017」新生舞会 内存限制:256 MiB时间限制:1500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  5. LoibreOJ 2042. 「CQOI2016」不同的最小割 最小割树 Gomory-Hu tree

    2042. 「CQOI2016」不同的最小割 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  6. LibreOJ #2006. 「SCOI2015」小凸玩矩阵 二分答案+二分匹配

    #2006. 「SCOI2015」小凸玩矩阵 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  7. 「NOI2018」你的名字

    「NOI2018」你的名字 题目描述 小A 被选为了\(ION2018\) 的出题人,他精心准备了一道质量十分高的题目,且已经 把除了题目命名以外的工作都做好了. 由于\(ION\) 已经举办了很多届 ...

  8. tyvj P2018 「Nescafé26」小猫爬山 解题报告

    P2018 「Nescafé26」小猫爬山 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 Freda和rainbow饲养了N只小猫,这天,小猫们要去爬山.经 ...

  9. LOJ #2585. 「APIO2018」新家

    #2585. 「APIO2018」新家 https://loj.ac/problem/2585 分析: 线段树+二分. 首先看怎样数颜色,正常的时候,离线扫一遍右端点,每次只记录最右边的点,然后查询左 ...

随机推荐

  1. if a != None:

    >>> x = 1 >>> not x False >>> x = [1] >>> not x False >>&g ...

  2. 2019南昌网络赛 hello 2019

    这道题和一道2017,2016的类似. A string t is called nice if a string “2017” occurs in t as a subsequence but a ...

  3. 动手实现CapsNet系列——2 实现(未完待续)

    执行后返回如下信息: Loading complete. Training started! [epoch 0][iter 0] loss: 0.8082, acc: 14.0000% (14/100 ...

  4. 在linux里面ps -ef | grep tomcat 什么意思

    linux中的查看和tomcat有关系的进程的命令 例如 [root@localhost bin]# ps -eaf | grep tomcat root 5091 1 0 23:04 pts/0 0 ...

  5. POCO的理解

    POCO的名称有多种,pure old clr object. plain ordinary clr object等 POCO的概念是指那些没有从任何类继承,也没有实现任何接口,更没有被其它框架侵入的 ...

  6. asp.net 大文件上传配置

    <system.web> <httpRuntime requestValidationMode=" ></httpRuntime> <!--单位:K ...

  7. Java入门笔记 07-枚举类

    介绍:在某些情况下,一个类的对象是有限且固定的,比如季节类,只有四个对象:春夏秋冬.这种实例有限而且固定的类,被称为枚举类.在JDK 5.0及以后,可以使用enum关键字定义枚举类,并且默认继承于ja ...

  8. HGAME 2020 misc

    week1 每日推荐 拿到Wireshark capture file后,按常规思路,用foremost命令拿到一个加密的压缩包,之后文件->导出对象->http,看到最大的一个文件里面最 ...

  9. Python学习(四)—— 列表和元组的类中方法

    列表 list:用中括号括起来,用“,”分割每个元素,列表中的元素可以是 数字.字符串.列表.布尔值......所有东西,可以说就是一个“集合” li = [1,3,5,'alex','age',[' ...

  10. tab 切换 和 BottomNavigationBar 自定义 底部导航条

    BottomNavigationBar 组件    BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold ...