C. Ayoub and Lost Array
链接
[https://codeforces.com/contest/1105/problem/C]
题意
给你n,表示数组长度,元素的值是l到r,问有多少种方案使得所有元素和整除3
分析
思维dp,看代码吧
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int N=2e5+10;
ll dp[N][3];//dp[i][j]表示l,r这个区间内i个数的和取余3等于j的方案数
int main(){
ll n,l,r;
//freopen("in.txt","r",stdin);
while(~scanf("%lld%lld%lld",&n,&l,&r)){
//容斥原理
int a=r/3-(l-1)/3;//l,r这个区间对3取余等于0的个数
int b=(r+2)/3-(l+1)/3;//l,r这个区间对3取余等于1的个数
int c=(r+1)/3-l/3;//l,r这个区间对3取余等于2的个数
dp[1][0]=a,dp[1][1]=b,dp[1][2]=c;
for(int i=2;i<=n;i++)
{
dp[i][0]=(dp[i-1][0]%mod*a%mod+dp[i-1][1]%mod*c%mod+dp[i-1][2]%mod*b%mod)%mod;
dp[i][1]=(dp[i-1][0]%mod*b%mod+dp[i-1][1]%mod*a%mod+dp[i-1][2]%mod*c%mod)%mod;
dp[i][2]=(dp[i-1][0]%mod*c%mod+dp[i-1][1]%mod*b%mod+dp[i-1][2]%mod*a%mod)%mod;
}
printf("%lld\n",dp[n][0]%mod);
}
return 0;
}
C. Ayoub and Lost Array的更多相关文章
- Codeforces 1105C: Ayoub and Lost Array(递推)
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...
- C. Ayoub and Lost Array cf dp
C. Ayoub and Lost Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 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 ...
- CF1105C Ayoub and Lost Array ——动态规划
CF1105C Ayoub and Lost Array 题意:一个整数数组,满足: 1. 长度为n 2. 所有元素都在[l, r]范围内 3. 所有元素的和能被3整除给出n, l, r (1 ≤ n ...
- Codeforces 1105C Ayoub and Lost Array (计数DP)
<题目链接> 题目大意: 有一个长度为 n 的数列的未知数列,数列的每一个数的值都在区间 [l,r] 的范围内.现在问你能够构成多少个这样的数组,使得数组内的所有数的和能够被 3 整除. ...
- C. Ayoub and Lost Array(DP)
(又是被队友带着上分的一场--) 题目链接:http://codeforces.com/contest/1105/problem/C 题目大意:给你n,l,r.每一个数都是在l,r范围之内,然后问你这 ...
- C. Ayoub and Lost Array Round #533 (Div. 2) 【DP】
一.题面 链接 二.分析 关于这题,两个点. 第一个点,是需要能够分析出$[L,R]$区间的3的余数的个数. 首先,可以得到,$[L,R]$区间内共有$(R-L+1)$个数. 设定余数为0,1,2的为 ...
- 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 ...
随机推荐
- Linux进程调度器概述--Linux进程的管理与调度(十五)
调度器面对的情形就是这样, 其任务是在程序之间共享CPU时间, 创造并行执行的错觉, 该任务分为两个不同的部分, 其中一个涉及调度策略, 另外一个涉及上下文切换. 1 背景知识 1.1 什么是调度器 ...
- 第十四届智能车培训 PLL锁相环
什么是锁相环? PLL(Phase Locked Loop): 为锁相回路或锁相环,用来统一整合时脉讯号,使高频器件正常工作,如内存的存取资料等.PLL用于振荡器中的反馈技术. 许多电子设备要正常工作 ...
- 使用freemarker生成静态页面
一 说明 需要在spring mvc项目中加入下列包: <dependency> <groupId>org.freemarker</groupId> <art ...
- 加一的golang实现
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 输入: [,,] ...
- excel数据表透视操作
虽然作为开发人员,很少用到office,但是在工作的时候,特别是做财务模块,或多或少都会用到excel处理数据,对比数据.比如说vlookup函数,数据透视表这些.vlookup函数我用得很熟练,但数 ...
- 面试----你可以手写一个promise吗
参考:https://www.jianshu.com/p/473cd754311f <!DOCTYPE html> <html> <head> <meta c ...
- 模拟placeholder
把这个记下来,主要是因为这里的 defaultValue 我之前竟然不知道 <input type="text" value="提示内容" onFocus ...
- AJAX问题 XMLHttpRequest.status = 0是什么含义
在调用AJAX的时候遇到了XMLHttpRequest. status为0 的情况,http协议里可是没这个状态码的,众所周知,XMLHttpRequest. Status为HTTP请求状态码,一般为 ...
- Unicode与UTF-8关系
Unicode字符集合 Unicode 也称为 UCS(Universal Coded Character Set:国际编码字符集合) 是一个字符集合. 对世界上大部分的文字系统进行了整理,编码,使电 ...
- go标准库的学习-errors
参考https://studygolang.com/pkgdoc 导入方式: import "errors" errors包实现了创建错误值的函数. 1)func New func ...