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 ...
随机推荐
- Zabbix监控文件是否存在/文件大小
检查C:\Zabbix\zabbix_agentd.log文件是否存在 zabbix_get -s 10.16.4.1 -k vfs.file.exists[C:\\Zabbix\\zabbix_ag ...
- Informix数据库配置与连接
1.环境 数据库版本:12.1 操作系统:Windows Server 2008 客户端:IBM Data Studio 4.1.3 2.配置 数据库安装后默认是无法远程访问的,需要修改sqlhost ...
- MyBatis动态SQL之一使用 if 标签和 choose标签
bootstrap react https://segmentfault.com/a/1190000010383464 xml 中 < 转义 to thi tha <if test=&qu ...
- 十大PHP程序员必备工具
十大PHP程序员必备工具 1.Notepad++ 总结来说就是小而精,7.4版本的软件包只有2.9M,比一般的IDE小数十倍,但是Notepad++的功能确是很全面的,代码高亮,语法折叠,宏功能,内置 ...
- Linux之命令初识
Linux与windows目录结构对比 命令mkdir.ls.ls -l.cd .pwd [root@oldboyedu-01 ~]# #创建目录 make directory mkdir [root ...
- I/O 机制的介绍(Linux 中直接 I/O 机制的介绍)
IO连接的建立方式 1.缓存IO.流式IO: 2.映射IO.块式IO: 3.直接IO. IO的方式: 同步.异步.定时刷新: MMAP与内核空间 mmap使用共享用户空间与内核空间实现: 直接 I/O ...
- YOLO 从数据集制作到训练
1.图片数据集收集 共 16种 集装箱船 container ship 散货船 bulker 油船 tanker 游轮 / 客轮 / 邮轮 passenger liner 渔船 fishing boa ...
- 测试中 unittest.main(verbosity=1) 是什么意思
这里的verbosity是一个选项,表示测试结果的信息复杂度,有三个值0 (静默模式): 你只能获得总的测试用例数和总的结果 比如 总共100个 失败20 成功801 (默认模式): 非常类似静默模式 ...
- angularjs处理/n转<br/>时候 <br/>不会解析的问题
$scope.name=$sce.trustAsHtml($scope.name); <p ng-bind-html="name"></p>
- 009_npm常用命令参数总结
npm是什么 NPM的全称是Node Package Manager,是随同NodeJS一起安装的包管理和分发工具,它很方便让JavaScript开发者下载.安装.上传以及管理已经安装的包. 一.np ...