Codeforces Round #533 C. Ayoub and Lost Array
题面:
题目描述:
题目分析:

当p == 0时:dp[0][n] += dp[0][n-1] * (第n位选被3模后余数为0的数的个数)dp[0][n] += dp[1][n-1] * (第n位选被3模后余数为2的数的个数)dp[0][n] += dp[2][n-1] * (第n位选被3模后余数为1的数的个数)当p == 1时:dp[0][n] += dp[0][n-1] * (第n位选被3模后余数为1的数的个数)dp[0][n] += dp[1][n-1] * (第n位选被3模后余数为0的数的个数)dp[0][n] += dp[2][n-1] * (第n位选被3模后余数为2的数的个数)当p == 2时:dp[0][n] += dp[0][n-1] * (第n位选被3模后余数为2的数的个数)dp[0][n] += dp[1][n-1] * (第n位选被3模后余数为1的数的个数)dp[0][n] += dp[2][n-1] * (第n位选被3模后余数为0的数的个数)
1-x中,被3取模后余数为0的数的个数:f0(x) = x / 31-x中,被3取模后余数为1的数的个数:f1(x) = (x + 2) / 31-x中,被3取模后余数为2的数的个数:f2(x) = (x + 1) / 3
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <algorithm>
6 using namespace std;
7 const long long mod = 1e9+7;
8 const long long maxn = 2e5+5;
9 long long n, l, r;
10
11 long long dp[5][maxn];
12
13 const int yu[3][3] = {{0, 2, 1}, {1, 0, 2}, {2, 1, 0}};
14
15
16 int main(){
17 cin >> n >> l >> r;
18 int t;
19
20 //注意初始化
21 for(int i = 0; i < 3; i++){
22 t = (3-i)%3;
23 dp[i][1] = ( (r+t)/3-(l+t-1)/3 );
24 }
25
26
27 for(int i = 2; i <= n; i++){
28 for(int k = 0; k < 3; k++){
29 for(int p = 0; p < 3; p++){
30 t = (3-yu[k][p]) % 3;
31 dp[k][i] += dp[p][i-1]*( (r+t)/3-(l+t-1)/3 ) % mod;
32 dp[k][i] %= mod;
33 }
34 }
35 }
36
37 cout << dp[0][n] << endl;
38
39 return 0;
40 }
Codeforces Round #533 C. Ayoub and Lost Array的更多相关文章
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- 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 ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...
- Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array(递推)
题意: 长为 n,由 l ~ r 中的数组成,其和模 3 为 0 的数组数目. 思路: dp[ i ][ j ] 为长为 i,模 3 为 j 的数组数目. #include <bits/stdc ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
- Codeforces Round #555 (Div. 3) E. Minimum Array 【数据结构 + 贪心】
一 题面 E. Minimum Array 二 分析 注意前提条件:$0 \le a_{i} \lt n$ 并且 $0 \le b_{i} \lt n$.那么,我们可以在$a_{i}$中任取一个数 ...
- 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 ...
随机推荐
- 修改jpg的图片大小
using System.Drawing.Imaging; public void ResizePic(string oldFilePath, int thumbnailImageWidth, int ...
- VS2010的单元测试(一)
在VS2010中,单元测试的功能很强大,使得建立单元测试和编写单元测试代码,以及管理和运行单元测试都变得简单起来,通过私有访问器可以对私有方法也能进行单元测试,并且支持数据驱动的单元测试. 一.创建单 ...
- P4213 【模板】杜教筛(杜教筛)题解
题意: 求\(\sum_{i=1}^n\varphi(i)\)和\(\sum_{i=1}^n\mu(i)\) 思路: 由性质可知:\(\mu*I=\epsilon,\varphi*I=id\)那么可得 ...
- Set DSL in Ubuntu 18.04
Reference Solutions: Ctrl+Atl+t Type nmcli con edit type pppoe con-name ANY_NAME_OF_DSL_YOU_LIKE, wh ...
- CSS字体大小: em与px、pt、百分比之间的对比
CSS样式最混乱的一个方面是应用程序中文本扩展的font-size属性.在CSS中,你可以用四个不同的单位度量来显示在web浏览器中的文本大小.这四个单位哪一种最适合Web? 这个问题引起了广泛的 ...
- bash variables plus operator All In One
bash variables plus operator All In One Errors missing pass params #!/usr/bin/env bash # echo emoji ...
- Versatile Python 3.x
Versatile Python 3.x TryPython Python 3.8.0 (default, Nov 14 2019, 22:29:45) [GCC 5.4.0 20160609] on ...
- js 垃圾回收 & js GC
js 垃圾回收 & js GC js GC / js Garbage Collector https://developer.mozilla.org/en-US/docs/Web/JavaSc ...
- Web SQL& IndexedDB
Web SQL& IndexedDB https://developer.mozilla.org/en/docs/Web/API/IndexedDB_API https://mdn.githu ...
- c++ win32 关机 注销 重启
#include <iostream> #include <Windows.h> #pragma comment(lib, "user32.lib") #p ...