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 ...
随机推荐
- C++ new delete malloc free
title: C++ new delete malloc free date: 2020-03-10 categories: c++ tags: 语法 C++的new delete malloc fr ...
- 云原生系列2 部署你的第一个k8s应用
云原生的概念和理论体系非常的完备,but talk is cheap , show me the code ! 但是作为一名程序员,能动手的咱绝对不多BB,虽然talk并不cheap , 能跟不同层次 ...
- vue 如何重绘父组件,当子组件的宽度变化时候
vue 如何重绘父组件,当子组件的宽度变化时候 vue & dynamic el-popover position demo https://codepen.io/xgqfrms/pen/wv ...
- React 性能优化 All In One
React 性能优化 All In One Use CSS Variables instead of React Context https://epicreact.dev/css-variables ...
- SwiftUI All In One
SwiftUI All In One SwiftUI SwiftUI is an innovative, exceptionally simple way to build user interfac ...
- TypeScript with React
TypeScript with React # Make a new directory $ mkdir react-typescript # Change to this directory wit ...
- Linux shell create file methods
Linux shell create file methods touch, cat, echo, EOF touch $ touch file.py $ touch file1.txt file2. ...
- js 裁剪图片
js 裁剪图片 https://gugeji.com/search?q=js剪切图片
- qt DateTime 计算时间
qdatetime doc 获取当前时间 QDateTime t1 = QDateTime::currentDateTime(); qDebug() << t1.toString(&quo ...
- Renice INC:解密干型葡萄酒
市场上,干型葡萄酒往往对比甜型葡萄酒(如甜红.甜白)受到更多葡萄酒爱好者的青睐.在葡萄酒界,大部分的红葡萄酒和白葡萄酒也都是干型的,而且它们的口感往往各有特色,并非千篇一律.今天,就跟随Renice ...