Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array(递推)
题意:
长为 n,由 l ~ r 中的数组成,其和模 3 为 0 的数组数目。
思路:
dp[ i ][ j ] 为长为 i,模 3 为 j 的数组数目。
#include <bits/stdc++.h>
using namespace std; const int M=220000;
const int mod=1e9+7; long long dp[M][3]; int main()
{
int n,l,r;cin>>n>>l>>r; for(int i=0;i<3;i++)
dp[1][i]=(r+3-i)/3-(l+3-i-1)/3; for(int i=2;i<=n;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
dp[i][j]=(dp[i][j]+dp[i-1][k]*dp[1][(3+j-k)%3]%mod)%mod; cout<<dp[n][0]; return 0;
}
参考:求区间内能被n整除%n==0,%n==1,%n==2....的个数
Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array(递推)的更多相关文章
- 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.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- 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) B. Zuhair and Strings 【模拟】
传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...
- Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
- Codeforces Round #533(Div. 2) B.Zuhair and Strings
链接:https://codeforces.com/contest/1105/problem/B 题意: 给一个字符串和k,连续k个相同的字符,可使等级x加1, 例:8 2 aaacaabb 则有aa ...
- 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 以内都满足 思路 ...
随机推荐
- Wi-Fi 6 与 5G 相比哪个更快?
随着 iPhone12 的发布,iOS 系统正式开始拥抱 5G,智能手机全面进入了 5G 时代.伴随着各大运营商的 5G 推广以及相关基站建设的如火如荼,5G 成了大家广泛讨论的热门词汇.这样热门的光 ...
- 【剑指 Offer】03.数组中重复的数字
题目描述 找出数组中重复的数字. 在一个长度为 n 的数组 nums 里的所有数字都在 0-n-1 的范围内.数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次.请找出数组中 ...
- 天梯赛练习 L3-008 喊山 (30分) bfs搜索
题目分析: 本题是一题比较简单的bfs搜索题,首先由于数据给的比较多不能直接开二维数组存放,而是用了vector的动态的二维数组的形式存放,对于每个出发点,我们bfs向四周搜索,标记搜索过的点,遇到搜 ...
- Linux echo和cat和grep和tr的基础用法
Linux vim 搜索 echo : 显示输出功能 echo oldboy>1.txtx cat 1.txtx > 重定向 文件内容覆盖 >> 追加重定向 ...
- Loadrunner参数化数据配置与更新方式
之前遇到过一种情况,对脚本进行并发测试时,脚本没有报错,但是有丢失的事物,与开发配合检查确定不是代码的问题,然后检查脚本,更换参数化数据配置与更新方式,问题解决.现在对参数化数据配置和更新方式进行总结 ...
- 别再问我们用什么画图的了!问就是excalidraw
每次发 https://github.com/tal-tech/go-zero 相关文章时,都会有读者问我们用什么画图的. 这图什么工具画的呀?好看! 这个手绘风格真好看,用啥工具画的呀? 可不可以介 ...
- linux中的虚拟环境工具
1.虚拟环境工具的学习 python的虚拟环境,其实就是在机器上,方便的创建出多个解释器,每个解释器运行一个项目,互相之间不受影响 2.virtualenv工具,可以方便的创建,使用,删除也很方便 3 ...
- Less中Css预处理器
Less.js 安装 npm install -g less 变量 basic 变量采用@进行变量定义.变量可以直接参加运算. @width:100px; .variables{ width:@wid ...
- 有状态(Stateful)应用的容器化 - 云+社区 - 腾讯云 https://cloud.tencent.com/developer/article/1020178
有状态(Stateful)应用的容器化 - 云+社区 - 腾讯云 https://cloud.tencent.com/developer/article/1020178
- file descriptor 0 1 2 一切皆文件 stdout stderr stdin /dev/null 沉默是金 pipes 禁止输出 屏蔽 stdout 和 stderr 输入输出重定向 重定向文件描述符
movie.mpeg.001 movie.mpeg.002 movie.mpeg.003 ... movie.mpeg.099 $cat movie.mpeg.0*>movie.mpeg ...