~~~题面~~~

题解:

  首先,有一个不太直观的状态,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. php Laravel5.5 表单验证常用的验证规则,以及示例

    namespace App\Http\Controllers; use App\Models\Users; use Illuminate\Support\Facades\Validator; use ...

  2. laravel -- 路由

    基本路由 Route::get('/get',function (){ return "this is get"; }); Route::post('/post',function ...

  3. python递归函数(计算阶乘)

    def f1(x,x1=1): if x == 1: return x1 #x1这个值为我们所需要的值,所以返回 x1 *= x r = f1(x-1,x1) #r接收返回值,并在下面接着返回 ret ...

  4. ctf题目writeup(4)

    2019.1.31 题目:这次都是web的了...(自己只略接触隐写杂项web这些简单的东西...) 题目地址:https://www.ichunqiu.com/battalion 1. 打开链接: ...

  5. mysql 筛选重复名称

    CREATE TABLE `blur_article` ( `id` ) NOT NULL, `name` ) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=In ...

  6. JENKINS系统的安装部署

    JENKINS 安装使用文档 简介 Jenkins是一个功能强大的应用程序,允许持续集成和持续交付项目,无论用的是什么平台.这是一个免费的源代码,可以处理任何类型的构建或持续集成,集成Jenkins可 ...

  7. 教你Zbrush 4R7怎样创建Z球

    随着CG行业的迅猛发展,就业门槛大幅度提高,对于从业人员要求就是要“又快又好”,作为一个模型师,常会碰到一天或两天完成一个全身角色的考题,而且还需要角度摆出造型,以前做这个的话,可能比较难,现在有了Z ...

  8. Android stadio bug

    好生气啊,android stadio 有bug.自己的代码,一直没有生效,原来是stadio 的问题.只是因为我打开了增强模式,后来,buildToolVersion 改了之后,android st ...

  9. c++返回引用

    #include <iostream> #include <ctime> using namespace std; double vals[] = {10.1, 12.6, 3 ...

  10. 29、phonegap入门

    0. PhoneGap介绍 0.1  什么是PhoneGap? PhoneGap是一个基于HTML.CSS.JS创建跨平台移动应程序的快速开发平台.与传统Web应用不同的是,它使开发者能够利用iPho ...