Hdu5181 numbers
numbers
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 196608/196608 K (Java/Others)
Total Submission(s): 154 Accepted Submission(s): 46
This question is quite easy. Therefore I must give you some limits.
There are m limits, each is expressed as a pair<A,B> means the number A must be popped before B.
Could you tell me the number of ways that are legal in these limits?
I know the answer may be so large, so you can just tell me the answer mod 1000000007(109+7).
Each test case begins with two integers n(1≤n≤300) and m(1≤m≤90000).
Next m lines contains two integers A and B(1≤A≤n,1≤B≤n)
(P.S. there may be the same limits or contradict limits.)
1 0
5 0
3 2
1 2
2 3
3 2
2 1
2 3
3 3
1 2
2 3
3 1
42
1
2
0
The only legal pop-sequence of case 3 is 1,2,3.
The legal pop-sequences of case 4 are 2,3,1 and 2,1,3.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
const ll maxn = ,mod = 1e9+;
ll f[maxn][maxn];
int T,n,m,sum[maxn][maxn][maxn],a[maxn][maxn][maxn];
bool flag = true; struct node
{
int x,y;
} e[]; void add(int x3,int y3,int x4,int y4,int k)
{
sum[x3][y3][k]++;
sum[x4 + ][y4 + ][k]++;
sum[x4 + ][y3][k]--;
sum[x3][y4 + ][k]--;
} void pre()
{
for (int i = ; i <= m; i++)
{
ll x = e[i].x,y = e[i].y;
if (x < y)
add(,y,x,n,x);
else
{
for (int j = y + ; j <= x; j++)
add(,x,y,n,j);
}
}
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
sum[i][j][k] = sum[i - ][j][k] + sum[i][j - ][k] - sum[i - ][j - ][k] + sum[i][j][k];
} void solve()
{
for (int i = ; i <= n; i++)
{
f[i][i] = ;
f[i][i - ] = ;
}
f[n + ][n] = ;
for (int len = ; len <= n; len++)
for (int i = ; i + len - <= n; i++)
{
int j = i + len - ;
for (int k = i; k <= j; k++)
{
if (sum[i][j][k] == )
{
f[i][j] += f[i][k - ] * f[k + ][j] % mod;
f[i][j] %= mod;
}
}
}
} int main()
{
scanf("%d",&T);
while(T--)
{
memset(sum,,sizeof(sum));
memset(f,,sizeof(f));
flag = true;
scanf("%d%d",&n,&m);
for (ll i = ; i <= m; i++)
{
scanf("%d%d",&e[i].x,&e[i].y);
if (e[i].x == e[i].y)
flag = false;
}
if (!flag)
puts("");
else
{
pre();
solve();
printf("%lld\n",f[][n] % mod);
}
} return ;
}
Hdu5181 numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
随机推荐
- 《Cocos2d-x游戏开发实战精解》学习笔记2--在Cocos2d-x中显示一行文字
在Cocos2d-x中要显示文字就需要用到Label控件.在3.x版本的Cocos2d中,舍弃了之前版本所使用的LabelTTF.LabelAtlas.LabelBMFont 3个用于显示文字的类,而 ...
- K-近邻算法入门
K-近邻算法的直观理解就是:给定一个训练集合,对于新的实例,在训练集合中找到k个与该实例最近的邻居,然后根据“少数服从多数”原则判断该实例归属于哪一类,又称“随大流” K-近邻算法的三大要素:K值得选 ...
- music, let's go
最近研究个新玩意,叫window.AudioContext;不懂?没关系,我也是才接触,这完全可以说个全新领域,这玩意干啥的?顾名思义,媒体上下文,也就是你媒体的数据分析,就是一串数据啊?那有啥用呢? ...
- 如何理解IPD+CMMI+Scrum一体化研发管理解决方案之CMMI篇
如何快速响应市场的变化,如何推出更有竞争力的产品,如何在竞争中脱颖而出,是国内研发企业普遍面临的核心问题,为了解决这些问题,越来越多的企业开始重视创新与研发管理,加强研发过程的规范化,集成产品开发(I ...
- scrum立会报告+燃尽图(第三周第六次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...
- 王者荣耀交流协会final发布WBS+PSP
WBS: PSP: 时间为估计,大致精确. 类型 personal software process stages 预估时间 实际花费时间 planning 计划 4h 4h estimate 4h ...
- java 中的 i=i++
记得大学刚开始学C语言时,老师就说:自增有两种形式,分别是i++和++i,i++表示的是先赋值后加1,++i是先加1后赋值,这样理解了很多年也没出现问题,直到遇到如下代码,我才怀疑我的理解是不是错了: ...
- java复利计算基本代码
源代码: public class Calculate { public static void main(String[] args){ double money = 1000; //本金 int ...
- 3dContactPointAnnotationTool开发日志(三十)
在vs2017里生成opencv时遇到了无法打开python27_d.lib的问题,具体解决请看这个,不过我用的是方法2,python37_d.lib找不到同理. Windows下可以用的op ...
- MAVEN项目标准目录结构 ;
http://blog.csdn.net/lengyue_wy/article/details/6718637 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.标准目录结构: src ...