~~~题面~~~

题解:

  首先,有一个不太直观的状态,f[i][j][k][l]表示DP到i位,三种颜色最后出现的位置分别是j, k, l的方案数。因为知道了三种颜色最后出现的位置,因此也可以得知以当前点为右端点的区间内有几种颜色了,因为左端点不断向左扩张的时候,颜色数不会减少。

  然后考虑优化这个状态,观察到因为每一位都必须有一个颜色,所以这3种颜色当中最后出现的那个所在的位置一定是当前的i。因此我们就可以去掉i,所以复杂度变成了$n^3$,就可以过此题了。

每次转移之前判断一下是否满足当前右端点的限制,如果不满足就continue,否则枚举颜色转移即可。

 #include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 302
#define ac 500
#define mod 1000000007
#define LL long long int n, m;
int Head[AC], date[ac], Next[ac], len[ac], tot;
LL f[AC][AC][AC], ans; inline int read()
{
int x = ;char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x;
} inline void add(int f, int w, int S)
{
date[++tot] = w, Next[tot] = Head[f], Head[f] = tot, len[tot] = S;
} inline void pre()
{
int a, b, c;
n = read(), m = read();
for(R i = ; i <= m; i ++)
{
a = read(), b = read(), c = read();
add(b, a, c);//以右端点为标准
}
} inline int Max(int x, int y, int z)
{
if(y > x) x = y;
if(z > x) x = z;
return x;
} inline bool check(int x, int y, int z)
{
if(x && y && x == y) return false;
if(x && z && x == z) return false;
if(y && z && y == z) return false;
int k = Max(x, y, z);
for(R i = Head[k]; i; i = Next[i])
{
int now = date[i], v = len[i], tmp = ;
if(x >= now) ++ tmp;
if(y >= now) ++ tmp;
if(z >= now) ++ tmp;
if(tmp != v) return false;
}
return true;
} void work()
{
f[][][] = ;
for(R i = ; i <= n; i ++)
for(R j = ; j <= n; j ++)
for(R l = ; l <= n; l ++)
{
int k = Max(i, j, l);
if(!f[i][j][l]) continue;
//printf("(%d, %d, %d) = %lld\n", i, j, l, f[i][j][l]);
if(!check(i, j, l)) continue;
LL t = f[i][j][l];
f[k + ][j][l] = (f[k + ][j][l] + t) % mod;
f[i][k + ][l] = (f[i][k + ][l] + t) % mod;
f[i][j][k + ] = (f[i][j][k + ] + t) % mod;
if(k == n) ans = (ans + f[i][j][l]) % mod;//必须到排到了n
}
printf("%lld\n", ans);
} int main()
{
freopen("in.in", "r", stdin);
pre();
work();
fclose(stdin);
return ;
}

ARC074 E RGB Sequence DP的更多相关文章

  1. AT2567 RGB Sequence dp

    正解:计数dp 解题报告: 传送门! umm其实我jio得dp的题目的话就难在思想昂,,,知道状态知道转移就不难辣QAQ 所以就不说别的了直接写下思路放下代码就over辣QAQ 最基础的思想就是f[i ...

  2. 【arc074e】RGB Sequence dp

    Description ​ 丰泽爷今天也在愉快地玩Minecraft! ​ 现在丰泽爷有一块1∗N1∗N的空地,每个格子按照顺序标记为11到NN.丰泽爷想要在这块空地上铺上红石块.绿宝石块和钻石块作为 ...

  3. 【arc074e】RGB Sequence(动态规划)

    [arc074e]RGB Sequence(动态规划) 题面 atcoder 洛谷 翻译见洛谷 题解 直接考虑暴力\(dp\),设\(f[i][j][k][l]\)表示当前考虑到第\(i\)位,最后一 ...

  4. [Arc074E] RGB Sequence

    [Arc074E] RGB Sequence Description 今天也在愉快地玩Minecraft!现在MM有一块1?N的空地,每个格子按照顺序标记为1到N.MM想要在这块空地上铺上红石块.绿宝 ...

  5. Atcoder E - RGB Sequence(dp)

    题目链接:http://arc074.contest.atcoder.jp/tasks/arc074_c 题意:一共有3种颜色,红色,绿色,蓝色.给出m个要求l,r,x表示在区间[l,r]内要有x种不 ...

  6. AT2567-[ARC074C]RGB Sequence【dp】

    正题 题目链接:https://www.luogu.com.cn/problem/AT2567 题目大意 长度为\(n\)的包含三种颜色\(RGB\)的序列,\(m\)个限制\([l,r,k]\)表示 ...

  7. [poj3017] Cut the Sequence (DP + 单调队列优化 + 平衡树优化)

    DP + 单调队列优化 + 平衡树 好题 Description Given an integer sequence { an } of length N, you are to cut the se ...

  8. Codeforces Round #277 (Div. 2) E. LIS of Sequence DP

    E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/pr ...

  9. [AT2567] [arc074_c] RGB Sequence

    题目链接 AtCoder:https://arc074.contest.atcoder.jp/tasks/arc074_c 洛谷:https://www.luogu.org/problemnew/sh ...

随机推荐

  1. 【mysql学习-1】

    part-1: #use mysql;/*show tables;select * from user;use mysql;show databases;#create database db1; # ...

  2. thinkphp3.2.3实现多条件查询实例.

    $data = M("datainfo"); $projectsname = I('get.projectsname');//前台提交的模糊查询字段 // 查询条件 $where ...

  3. python函数(2017-8-2)

    1. def 函数名(形式参数) 函数体 return "123" 函数执行了return之后就不再执行下面的代码 2. 默认形参实参的位置一一对应 如果要调整位置,指定形参名字 ...

  4. Leecode刷题之旅-C语言/python-1.两数之和

    开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...

  5. ctf题目writeup(2)

    2019.1.29 题目地址: https://www.ichunqiu.com/battalion 1. 点开链接: include "flag.php";$a = @$_REQ ...

  6. Kubernetes-tutorials(五)

    The tutorials use Katacoda to run a virtual terminal in your web browser that runs Minikube, a small ...

  7. ChipScope软件使用

    内容组织 1.建立工程  2.插入及配置核  2.1运行Synthesize  2.2新建cdc文件  2.3 ILA核的配置  3. Implement and generate programmi ...

  8. Moodle的安装和登陆(使用Https)

    之前使用默认的配置和安装,到中间检测组件是,总是提示  site no https.所以重新安装,用:https://localhost来登陆,结果不再提示,所以建议大家在使用时,还是用https来登 ...

  9. java Spring boot使用spring反射

    spring 反射 当你配置各种各样的bean时,是以配置文件的形式配置的,你需要用到哪些bean就配哪些,spring容器就会根据你的需求去动态加载,你的程序就能健壮地运行. 1.可以通过类名去实例 ...

  10. 关于实现mybatis order by 排序传递参数实现 问题记录

    一    问题场景:本人项目纯纯的后端系统  并且项目前端采用纯纯的原生js 实现 1)表格  通过查询列表数据放入到域中  前段采用 for循环的方式实现遍历生成列表 2)分页实现本人是公司内部自定 ...