HZOJ matrix
完全没有思路,状压到死没调出来……吐槽一下这题目描述的好不清楚啊好多人都理解错题了……
题解:
真的挺神仙的,因为有每列最多放1个的限制,所以考虑按列dp,设f[i][j]表示考虑前i列在[1,i]中的右区间中有j个1,初始状态f[0][0]=1;注:以下右区间表示[r[u],m];
记录l,r的前缀和sl,sr,但是这两个数组的含义并不一样,sl[i]表示前i列中有多少行左区间已经结束,sr[i]表示的则是前i列中有多少行右区间已经开始。
转移:首先只考虑第i列,枚举右区间1的个数j,如果第i列不放1,那么$f[i][j]+=f[i-1][j]$,如果第i列放1,现在不考虑前i-1列的应响,$f[i][j]+=f[i-1][j-1]*(sr[i]-j+1)$,这里解释一下这个$sr[i]-j+1$,在前i列包括sr[i]行的右区间可以放1,而前i-1列已经放了$j-1$个1占据了$(j-1)$行,所以第i列能放1的行数为$(sr[i]-(j-1))$,由乘法计数原理得以上式子。但是我们这是没有考虑前i列左区间的情况:同样枚举右区间放k个1,此时有(sl[i]-sl[i-1])个左区间在第i列结尾,所以此时有(sl[i]-sl[i-1])个1必须要放,而有i-k-sl[i-1]个位置可以放1,所以要乘$A_{i-k-sl[i-1]}^{sl[i]-sl[i-1]}$,如果不合法会变成负数。最后f[m][n]即为最后答案。
#include<iostream>
#include<cstdio>
#define LL long long
#define int LL
#define mod 998244353
#define MAXN 3010
using namespace std;
int n,m,l[MAXN],r[MAXN];
int sl[MAXN],sr[MAXN],f[MAXN][MAXN];
signed main()
{
cin>>n>>m;
for(int i=;i<=n;i++)cin>>l[i]>>r[i],sl[l[i]]++,sr[r[i]]++;
for(int i=;i<=m;i++)sl[i]+=sl[i-],sr[i]+=sr[i-];
f[][]=;
for(int i=;i<=m;i++)
{
f[i][]=f[i-][];
for(int j=;j<=i;j++)
f[i][j]=(f[i-][j]+f[i-][j-]*(sr[i]-j+)%mod)%mod;
for(int k=;k<=i;k++)
for(int j=sl[i-];j<sl[i];j++)
f[i][k]=f[i][k]*(i-k-j)%mod;
}
printf("%lld\n",f[m][n]);
}
HZOJ matrix的更多相关文章
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...
- Atitit Data Matrix dm码的原理与特点
Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...
- Android笔记——Matrix
转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...
- 通过Matrix进行二维图形仿射变换
Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...
- [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...
- [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
- [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- [LeetCode] Search a 2D Matrix 搜索一个二维矩阵
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
随机推荐
- 关于display:flex;兼容写法
display: -moz-box; /* Firefox */ display: -ms-flexbox; /* IE10 */ display: -webkit-box; /* Safari */ ...
- mysql hibernate 查询ip地址在mysql的网段
买的数据库,地址是字符串格式 如何查询一个确定的ip在哪里呢? 直接通过字符串查询估计要慢死了 可以先把自己的要查询的ip转换为数字,然后再去以数字的方式查询 IP转数字1.2.6.0转为数字 SEL ...
- jedis与spring整合及简单的使用RedisTemplate操作
整理一下redis与spring的整合.以及使用redisTemplate.首先是要导入spring所需要的jar.当然还有 jedis-2.1.0.jar,commons-pool-1.5.4.ja ...
- LUOGU P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- web前端学习(三)css学习笔记部分(5)-- CSS动画--页面特效、HTML与CSS3简单页面效果实例
CSS动画--页面特效部分内容目前仅仅观看了解内容,记录简单笔记,之后工作了进行内容的补充 7. CSS动画--页面特效 7.1 2D.3D转换 7.1.1 通过CSS3转换,我们能够对元素进行 ...
- LintCode刷题笔记--Longest Increasing Subsequence
标签: 动态规划 描述: Given a sequence of integers, find the longest increasing subsequence (LIS). You code s ...
- Oracle 行转列及列转行
参考网址:http://blog.163.com/fushahui_1988@126/blog/static/82879994201192844355174/ 一.多行转一列select id, vn ...
- 【JZOJ4461】【GDOI2016模拟4.21】灯塔 分治
题面 GDOI是一个地处丘陵的小国,为了边防建设,国王希望在国界线上的某一座山峰上建立一座灯塔,照亮整个边界.而灯塔建设的调研工作,就交给了你. GDOI的国境线上有N座连续的山峰,其中第i座的高度是 ...
- at: 安排一个任务在未来执行,需要一个atd的系统后台进程
检查atd进程是否启动 [root@centos61 桌面]# service atd status atd (pid 2274) 正在运行... [root@centos61 桌面]# chkco ...
- php中array_slice和array_splice函数解析方式方法
array_slice array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_k ...