链接: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)

剩下同理

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = 2*1e5+10;
  5. const int MOD = 1e9+7;
  6. LL dp[MAXN][3];
  7.  
  8. int main()
  9. {
  10. int n,l,r;
  11. cin >> n >> l >> r;
  12. dp[0][0] = 1,dp[0][1] = 0,dp[0][2] = 0;
  13. int mod0 = r/3-(l-1)/3,mod1 = (r+2)/3-(l+1)/3,mod2 = (r+1)/3-(l)/3;
  14. for (int i = 1;i<=n;i++)
  15. {
  16. dp[i][0] = (dp[i-1][0]*mod0%MOD+dp[i-1][1]*mod2%MOD+dp[i-1][2]*mod1%MOD)%MOD;
  17. dp[i][1] = (dp[i-1][0]*mod1%MOD+dp[i-1][1]*mod0%MOD+dp[i-1][2]*mod2%MOD)%MOD;
  18. dp[i][2] = (dp[i-1][0]*mod2%MOD+dp[i-1][1]*mod1%MOD+dp[i-1][2]*mod0%MOD)%MOD;
  19. }
  20. cout << dp[n][0] << endl;
  21.  
  22. return 0;
  23. }

  

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. LwIP移植uCos+stm32f407

    LwIP同操作系统一起工作的时候模型如下: 1.TCP/IP协议栈和应用程序以分离的任务运行 2.应用同协议栈沟通是通过API函数调用(API函数调用事实上就是通过OS自带的进程间通信机制,由应用程序 ...

  2. Vue的watch和computed属性

    Vue的watch属性 Vue的watch属性可以用来监听data属性中数据的变化 <!DOCTYPE html> <html> <head> <meta c ...

  3. 最优配对问题(集合上的动态规划) —— 状压DP

    题目来源:紫书P284 题意: 给出n个点的空间坐标(n为偶数, n<=20), 把他们配成n/2对, 问:怎样配对才能使点对的距离和最小? 题解: 设dp[s]为:状态为s(s代表着某个子集) ...

  4. codevs 1214线段覆盖

    1214 线段覆盖  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description 给定x轴上的N(0<N<100)条线段,每 ...

  5. python装饰器执行顺序

    . python 装饰器 1) 2层装饰器 def decorator(func): # TODO def wrapper(*args, **kwargs): # TODO func(*args, * ...

  6. bzoj 4589 Hard Nim —— FWT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4589 先手必败,是一开始所有石子的异或和为0: 生成函数 (xpri[1] + xpri[2 ...

  7. unittest执行测试用例的N种姿势总结

    1.我们写几个方法,用来做测试用例 2.我们在另一文件中引用这个模块下面的所有类方法,先看第一种方法: 运行结果: 缺点:每个用例都需要加载到测试套件中,如果有1000个用例,要写1000次重复的代码 ...

  8. html+css构成的框架,可自行改造

    运行效果 代码下载地址:http://pan.baidu.com/s/1eSeBh2E

  9. HDOJ-2034

    人见人爱A-B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  10. sql语句之正则表达式

    select * from employee where name regexp '^jin' select * from employee where name regexp '^jin.*(g|n ...