HDU6578 2019HDU多校训练赛第一场 1001 (dp)
HDU6578 2019HDU多校训练赛第一场 1001 (dp)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578
题意:
你有n个空需要去填,有m个限制,每次限制要求在区间[l,r]内不同的点的个数是为x个,问你填完这n个空的并且满足限制的方案数
题解:
定义\(dp[i][j][k][t]\)表示在区间填完前t个位置后,{0,1,2,3}这四个数字最后一次出现的位置为i,j,k,t的方案数
滚动数组优化掉第一维后,我们转移如下
dp[p][j][k][t] += dp[p ^1][j][k][t];
dp[p][i - 1][k][t] += dp[p ^ 1][j][k][t];
dp[p][i - 1][j][t] += dp[p ^ 1][j][k][t];
dp[p][i - 1][j][k] += dp[p ^ 1][j][k][t];
当然 这个时候我们求的是所有的区间,所以我们需要去掉不合法的区间
去重的时候判断左右端点组成的区间和x是否相符即可
代码:
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 3e2 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const double Pi = acos(-1);
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
LL lcm(LL a, LL b) {
return a / gcd(a, b) * b;
}
double dpow(double a, LL b) {
double ans = 1.0;
while(b) {
if(b % 2)ans = ans * a;
a = a * a;
b /= 2;
} return ans;
}
LL quick_pow(LL x, LL y) {
LL ans = 1;
while(y) {
if(y & 1) {
ans = ans * x % mod;
} x = x * x % mod;
y >>= 1;
} return ans;
}
vector<pii> vec[maxn];
int dp[2][maxn][maxn][maxn];
void MOD(int &x) {
if(x >= mod) x -= mod;
}
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int T;
scanf("%d", &T);
while(T--) {
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
vec[i].clear();
}
for(int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
vec[r].push_back(make_pair(l, x));
}
dp[0][0][0][0] = 1;
for(int i = 1, p = 1; i <= n; i++, p ^= 1) {
for(int j = 0; j <= i; j++) {
for(int k = 0; k <= j; k++) {
for(int t = 0; t <= k; t++) {
dp[p][j][k][t] = 0;
}
}
}
for(int j = 0; j < i; j++) {
for(int k = 0; k <= j; k++) {
for(int t = 0; t <= k; t++) {
MOD(dp[p][j][k][t] += dp[p ^ 1][j][k][t]);
MOD(dp[p][i - 1][k][t] += dp[p ^ 1][j][k][t]);
MOD(dp[p][i - 1][j][t] += dp[p ^ 1][j][k][t]);
MOD(dp[p][i - 1][j][k] += dp[p ^ 1][j][k][t]);
}
}
}
for(int j = 0; j < i; j++) {
for(int k = 0; k <= j; k++) {
for(int t = 0; t <= k; t++) {
for (auto tmp : vec[i]) {
//不合法区间,清零
if (1 + (j >= tmp.first) + (k >= tmp.first) + (t >= tmp.first) != tmp.second) {
dp[p][j][k][t] = 0;
}
}
}
}
}
}
int ans = 0;
for (int i = 0, p = n & 1; i < n; i ++)
for (int j = 0; j <= i; j ++)
for (int k = 0; k <= j; k ++)
MOD(ans += dp[p][i][j][k]);
printf("%d\n", ans);
}
return 0;
}
HDU6578 2019HDU多校训练赛第一场 1001 (dp)的更多相关文章
- HDU6579 2019HDU多校训练赛第一场1002 (线性基)
HDU6579 2019HDU多校训练赛第一场1002 (线性基) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题意: 两种操作 1.在序列末 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)
Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...
- 10.29训练赛第一场B题
题目大意:有n个队伍之间比赛,每两个队伍之间都有一场比赛,因此一共有n(n-1) / 2场比赛,但是这里丢失了一场比赛的记录,现在让你通过n(n-1) /2 -1场仍然存在的比赛记录来判断丢失的那条比 ...
- 2015 多校赛 第一场 1001 (hdu 5288)
Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l&l ...
- 2019HDU多校训练第三场 Planting Trees 暴力 + 单调队列优化
题意:有一个n * n的网格,每个网格中间有一颗树,你知道每棵树的高,你可以选择一个矩形区域把里面的树都围起来,但是矩形区域里面任意两棵树的高度差的绝对值不超过m,问这个矩形的最大面积是多少? 思路: ...
- 训练赛第一场D题
解题报告:一开始不知道ATA的意思,后来才知道原来是转置矩阵乘以原来的矩阵.这题说起来比较麻烦就不说了,直接上代码: #include<cstdio> #include<cstrin ...
- 训练赛第一场A题 (ZOJ 2313)
解题报告:n个人围坐成一圈,并且将这n个人从1到n编号,然后编号为1 的人手上有一个物品,将这个物品往向左传递给第k个人,1<=k<=n/2,当这个物品再次传到编号为1 的人的手上时,游戏 ...
- 2019HDU多校第一场1001 BLANK (DP)(HDU6578)
2019HDU多校第一场1001 BLANK (DP) 题意:构造一个长度为n(n<=10)的序列,其中的值域为{0,1,2,3}存在m个限制条件,表示为 l r x意义为[L,R]区间里最多能 ...
随机推荐
- 【C++】判断一个图是否有环 无向图 有向图(转载)
没有找到原文出处,请参考一下链接: http://www.cnblogs.com/hiside/archive/2010/12/01/1893878.html http://topic.csdn.ne ...
- docker+jenkins的实现方式(ps.使用dockerfile的方式)!
继http://www.cnblogs.com/guilty/p/4747993.html之后. 前两天朋友问的,docker+jenkins整合. 我也没搞过,但是正好最近有空,我也很有兴趣,就搞一 ...
- 部署zabbix3.2.7,升级到3.4、proxy部署
一.Server安装 可以使用mysql.percona.mariadb等,本例使用mariadb.由于是事后整理,只截取部分命令. #yum install mariadb-server maria ...
- 如何编写go代码
go是一种静态编译型的语言,它的编译速度非常快. go的官方编译器称为gc,包括编译工具5g,6g和8g,连接工具5l,6l和8l.其中的数字表示处理器的架构.我们不必关心如何挑选这些工具,因为go提 ...
- 亚洲唯一,阿里云SLB位列Gartner全球网络负载均衡市场前五
近日,Gartner发布了最新的全球企业级网络设备市场份额报告“Market Share: Enterprise Network Equipment by Market Segment, Worldw ...
- du,df区别
1.记住命令 du:disk Usage -h, --human-readable print sizes in human readable format df:disk free 2.区别 du ...
- POJ-1125_Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...
- Open Source GIS and Freeware GIS Applications
Open Source GIS and Freeware GIS Applications An open source application by definition is software ...
- 关于react-router 路径改变页面没有刷新
routert.js 中: <Router> <Switch> <Route exact path="/" component={Login}> ...
- PyTorch 学习笔记(四):权值初始化的十种方法
pytorch在torch.nn.init中提供了常用的初始化方法函数,这里简单介绍,方便查询使用. 介绍分两部分: 1. Xavier,kaiming系列: 2. 其他方法分布 Xavier初始化方 ...