[Arc074E] RGB Sequence
[Arc074E] RGB Sequence
Description
今天也在愉快地玩Minecraft!现在MM有一块1?N的空地,每个格子按照顺序标记为1到N。MM想要在这块空地上铺上红石块、绿宝石块和钻石块作为装饰。每个格子只能选择一种方块。MM有自己的审美标准。他定下了M条规定,每条规定形如(li,ri,xi),表示闭区间[li,ri]中,需要有恰好xi种不同的方块。MM觉得这个任务实在是太简单了,于是把它交给了你,但是你发现有太多种方式可以满足MM的审美需求了!于是你希望先知道,一共有多少铺方块的方法,可以满足MM的审美需求?答案对109+7取模
Input
第一行两个整数,N,M
接下来M行,每行三个整数li,ri,xi
Output
一个整数,对109+7取模后的答案
Sample Input
Case 1:3 1
1 3 3
Case 2:4 2
1 3 1
2 4 2
Case 3:1 3
1 1 1
1 1 2
1 1 3
Case 4:8 10
2 6 2
5 5 1
3 5 2
4 7 3
4 4 1
2 3 1
7 7 1
1 5 2
1 7 3
3 4 2
Sample Output
Case 1:6
Case 2:6
Case 3:0
Case 4:108
HINT
1≤N,M≤300
1≤li≤ri≤N
1≤xi≤3
试题分析
设\(f{i,j,k}\)表示填到第i位,另外两种颜色最后一次涂在\(\{j,k\}\)的方案数。
在右端点判断不合法情况,转移即可。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
inline int read(){
int x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int INF = 2147483600;
const int MAXN = 100010;
const int Mod = 1e9+7;
int N,M;
struct data{
int l,x; data(int ll=0,int xx=0){
l=ll; x=xx;
}
}; vector<data> vec[MAXN+1];
inline bool check(int i,int j,int k){
for(int l=0;l<vec[i].size();l++){
int cnt=1; if(vec[i][l].l<=j) ++cnt;
if(vec[i][l].l<=k) ++cnt;
if(cnt!=vec[i][l].x) return false;
} return true;
}int f[301][301][301];
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
N=read(),M=read();
for(int i=1;i<=M;i++){
int l=read(),r=read(),x=read();
vec[r].push_back(data(l,x));
} f[0][0][0]=1;
for(int i=0;i<N;i++){
for(int j=0;j<(i==0?1:i);j++){
for(int k=0;k<(j==0?1:j);k++){
if(!check(i,j,k)){f[i][j][k]=0; continue;}
(f[i+1][i][j]+=f[i][j][k])%=Mod;
(f[i+1][i][k]+=f[i][j][k])%=Mod;
(f[i+1][j][k]+=f[i][j][k])%=Mod;
}
}
} int ans=0;
for(int i=0;i<=N;i++){
for(int j=i+1;j<=N;j++)
if(check(N,j,i)) (ans+=f[N][j][i])%=Mod;
}if(check(N,0,0)) (ans+=f[N][0][0])%=Mod;
printf("%d\n",ans);
return 0;
}
[Arc074E] RGB Sequence的更多相关文章
- 【arc074e】RGB Sequence(动态规划)
[arc074e]RGB Sequence(动态规划) 题面 atcoder 洛谷 翻译见洛谷 题解 直接考虑暴力\(dp\),设\(f[i][j][k][l]\)表示当前考虑到第\(i\)位,最后一 ...
- 【ARC074e】RGB sequence
Description 一排\(n\)个格子,每个格子可以涂三种颜色的一种.现在给出\(m\)个形如"\([l,r]\)中必须恰好有\(x\)种颜色"的限制(\(1 \le l ...
- 【arc074e】RGB Sequence dp
Description 丰泽爷今天也在愉快地玩Minecraft! 现在丰泽爷有一块1∗N1∗N的空地,每个格子按照顺序标记为11到NN.丰泽爷想要在这块空地上铺上红石块.绿宝石块和钻石块作为 ...
- AtCoder - 2567 RGB Sequence
Problem Statement There are N squares arranged in a row. The squares are numbered 1, 2, …, N, from l ...
- AT2567-[ARC074C]RGB Sequence【dp】
正题 题目链接:https://www.luogu.com.cn/problem/AT2567 题目大意 长度为\(n\)的包含三种颜色\(RGB\)的序列,\(m\)个限制\([l,r,k]\)表示 ...
- AT2567 RGB Sequence dp
正解:计数dp 解题报告: 传送门! umm其实我jio得dp的题目的话就难在思想昂,,,知道状态知道转移就不难辣QAQ 所以就不说别的了直接写下思路放下代码就over辣QAQ 最基础的思想就是f[i ...
- [AT2567] [arc074_c] RGB Sequence
题目链接 AtCoder:https://arc074.contest.atcoder.jp/tasks/arc074_c 洛谷:https://www.luogu.org/problemnew/sh ...
- ARC074 E RGB Sequence DP
---题面--- 题解: 首先,有一个不太直观的状态,f[i][j][k][l]表示DP到i位,三种颜色最后出现的位置分别是j, k, l的方案数.因为知道了三种颜色最后出现的位置,因此也可以得知以当 ...
- AtCoder Regular Contest 074 E:RGB Sequence
题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_c 题目翻译 给你一行\(n\)个格子,你需要给每个格子填红绿蓝三色之一,并且同时满足\(m\ ...
随机推荐
- querySelector()与querySelectorAll()
1.querySelector() 参数:css选择器 返回匹配指定css选择器元素的第一个子元素 2.querySelectorAll() 参数:css选择器 返回匹配指定css选择器的所有元素
- url编码模块
use LWP::SImple; use URI::Escape; encoded_string = uri_escape(raw_string); get(encoded_string);
- Python模块学习 - Functools
Functools模块 Higher-order functions and operations on callable objects,看这个标题我都是懵逼的,这都是啥啥啥啊,赶紧拿出百度翻译:可 ...
- [Linux]Linux printf 输出重定向【转】
转自:http://www.cnblogs.com/aaronLinux/p/6765145.html?utm_source=itdadao&utm_medium=referral 方法一 # ...
- sunos kernel src
https://github.com/eocallaghan/AuroraUX-SunOS https://github.com/zoyanhui/coroutine-libtask https:// ...
- 如何用jQuery获得radio的值
如何获得radio的值,在网上查了一下,下面总结几种解决方法,. 1.获取选中值: $('input:radio:checked').val(): $("input[type='radio' ...
- apache的扩展模块安装
/* 当需要用到Apache的扩展模块时, 就要用到了apache的扩展工具 apxs */ #在使用这个功能之前,请先确认是否已经加载了 mod_so 模块,方法是: [root@localhost ...
- EXT入门学习
今天,对EXT做了一下初步的了解,了解了一些基本用的函数.窗体对象.表单.文本域.按钮,一些基本的函数我列了出来,写了个登陆的demo,是根据别人的例子模仿出来的,见谅哈. 基本函数 Ext.onRe ...
- 高性能网络服务器--I/O复用 select poll epoll_wait之间的区别
一.select select采用的是集合的方式,最多只能访问1024个套接字.可读,可写,异常,三种访问,并且采用的是轮训的方式进行每次访问都需要从内核向用户空间拷贝 二.poll poll采用的是 ...
- POJ-2398
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4243 Accepted: 2517 Descr ...