链接:https://codeforces.com/contest/1105/problem/C

题意:

给n,l,r。

一个n长的数组每个位置可以填区间l-r的值。

有多少种填法,使得数组每个位置相加的和是3的倍数

思路:

赛后看代码都看不懂的题。

dp,

从1个数组扩展到n个数组,

dp[i][j]是加上第i个数组后,分别余0,1,2的个数。

余0则是,i-1余0*自己余0+(i-1余1*自己余2)+(i-1余2*自己余1)

剩下同理

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2*1e5+10;
const int MOD = 1e9+7;
LL dp[MAXN][3]; int main()
{
int n,l,r;
cin >> n >> l >> r;
dp[0][0] = 1,dp[0][1] = 0,dp[0][2] = 0;
int mod0 = r/3-(l-1)/3,mod1 = (r+2)/3-(l+1)/3,mod2 = (r+1)/3-(l)/3;
for (int i = 1;i<=n;i++)
{
dp[i][0] = (dp[i-1][0]*mod0%MOD+dp[i-1][1]*mod2%MOD+dp[i-1][2]*mod1%MOD)%MOD;
dp[i][1] = (dp[i-1][0]*mod1%MOD+dp[i-1][1]*mod0%MOD+dp[i-1][2]*mod2%MOD)%MOD;
dp[i][2] = (dp[i-1][0]*mod2%MOD+dp[i-1][1]*mod1%MOD+dp[i-1][2]*mod0%MOD)%MOD;
}
cout << dp[n][0] << endl; return 0;
}

  

Codeforces Round #533(Div. 2) C.Ayoub and Lost Array的更多相关文章

  1. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】

    传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...

  2. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array(递推)

    题意: 长为 n,由 l ~ r 中的数组成,其和模 3 为 0 的数组数目. 思路: dp[ i ][ j ] 为长为 i,模 3 为 j 的数组数目. #include <bits/stdc ...

  3. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  4. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  5. Codeforces Round #533 (Div. 2) Solution

    A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...

  6. Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】

    传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...

  7. Codeforces Round #533(Div. 2) D.Kilani and the Game

    链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...

  8. Codeforces Round #533(Div. 2) B.Zuhair and Strings

    链接:https://codeforces.com/contest/1105/problem/B 题意: 给一个字符串和k,连续k个相同的字符,可使等级x加1, 例:8 2 aaacaabb 则有aa ...

  9. Codeforces Round #533(Div. 2) A.Salem and Sticks

    链接:https://codeforces.com/contest/1105/problem/A 题意: 给n个数,找到一个数t使i(1-n)∑|ai-t| 最小. ai-t 差距1 以内都满足 思路 ...

随机推荐

  1. Python 参数校验的进化

    Python 函数参数魔法 事情的起因是感觉目前项目中的参数校验方法写的太简单了,很多时候需要在server层再if else处理,于是就动手准备写一个好用一点的,可以自定义校验参数规则的参数校验器, ...

  2. Long转换为date

    public static void main(String[] args) { Long time = System.currentTimeMillis(); System.out.println( ...

  3. Linux系统中10个常用的ps命令总结

    Linux作为Unix的衍生操作系统,Linux内建有查看当前进程的工具ps.这个工具能在命令行中使用PS 命令是什么 查看它的man手册可以看到,ps命令能够给出当前系统中进程的快照.它能捕获系统在 ...

  4. lvs+keepalived+nginx高性能负载均衡集群

    项目发布时候,别人还能访问呢? 双机主从热备 LVS作用 LVS是一个开源的软件,可以实现传输层四层负载均衡.LVS是Linux Virtual Server的缩写,意思是Linux虚拟服务器.目前有 ...

  5. hdu 1029 Ignatius and the Princess IV(排序)

    题意:求出现次数>=(N+1)/2的数 思路:排序后,输出第(N+1)/2个数 #include<iostream> #include<stdio.h> #include ...

  6. Springboot框架中request.getInputStream()获取不到上传的文件流

    Springboot框架中用下面的代码,使用request.getInputStream()获取不到上传的文件流 @PostMapping("/upload_img") publi ...

  7. codeforces 664C C. International Olympiad(数学)

    题目链接: C. International Olympiad time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. ubuntu 下编译安装ceph

    git clone --recursive https://github.com/ceph/ceph.git  cd ceph/  sudo apt-get install libtool   sud ...

  9. 【CQ18高一暑假前挑战赛4】标程

    [二分或者STL] 二分: #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int main() { ,pos; s ...

  10. Java操作系统硬件的方法Unsafe

    通常Java代码都是运行在JVM中而不能直接访问系统硬件如进行内存分配释放等,但如果有需要跳过JVM直接用Java访问系统硬件,比如像C语言指针一样操作的话就可以调用Unsafe对象相关方法. 1.U ...