C. Ayoub and Lost Array cf dp
1 second
256 megabytes
standard input
standard output
Ayoub had an array aa of integers of size nn and this array had two interesting properties:
- All the integers in the array were between ll and rr (inclusive).
- The sum of all the elements was divisible by 33 .
Unfortunately, Ayoub has lost his array, but he remembers the size of the array nn and the numbers ll and rr , so he asked you to find the number of ways to restore the array.
Since the answer could be very large, print it modulo 109+7109+7 (i.e. the remainder when dividing by 109+7109+7 ). In case there are no satisfying arrays (Ayoub has a wrong memory), print 00 .
The first and only line contains three integers nn , ll and rr (1≤n≤2⋅105,1≤l≤r≤1091≤n≤2⋅105,1≤l≤r≤109 ) — the size of the lost array and the range of numbers in the array.
Print the remainder when dividing by 109+7109+7 the number of ways to restore the array.
2 1 3
3
3 2 2
1
9 9 99
711426616
In the first example, the possible arrays are : [1,2],[2,1],[3,3][1,2],[2,1],[3,3] .
In the second example, the only possible array is [2,2,2][2,2,2] .
这个题目先要意识到这是一个动态规划
他是在范围内取一个元素个数为n,对3的余数为0的集合的方案数。
这个就可以当初一种动态规划,从1到n转移。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+;
ll mod=1e9+,dp[maxn][];//dp[i][j]代表余数为j时,集合元素为i的方案数 int main()
{
int n,l,r,a=,b=,c=;
cin>>n>>l>>r;
int k=(r-l)/;
a=b=c=k;
for(int i=l+*k;i<=r;i++)
{
if(i%==) a++;
if(i%==) b++;
if(i%==) c++;
}
dp[][]=a;
dp[][]=b;
dp[][]=c;
for(int i=;i<=n;i++)
{
dp[i][]=dp[i-][]*a%mod;
dp[i][]%=mod;
dp[i][]+=dp[i-][]*c%mod;
dp[i][]%=mod;
dp[i][]+=dp[i-][]*b%mod;
dp[i][]%=mod;
dp[i][]=dp[i-][]*b%mod;
dp[i][]%=mod;
dp[i][]+=dp[i-][]*a%mod;
dp[i][]%=mod;
dp[i][]+=dp[i-][]*c%mod;
dp[i][]%=mod;
dp[i][]=dp[i-][]*c%mod;
dp[i][]%=mod;
dp[i][]+=dp[i-][]*b%mod;
dp[i][]%=mod;
dp[i][]+=dp[i-][]*a%mod;
dp[i][]%=mod;
}
cout<<dp[n][]<<endl;
return ;
}
C. Ayoub and Lost Array cf dp的更多相关文章
- 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 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范围之内,然后问你这 ...
- Codeforces 1105C: Ayoub and Lost Array(递推)
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...
- CF1105C Ayoub and Lost Array ——动态规划
CF1105C Ayoub and Lost Array 题意:一个整数数组,满足: 1. 长度为n 2. 所有元素都在[l, r]范围内 3. 所有元素的和能被3整除给出n, l, r (1 ≤ n ...
- C. Ayoub and Lost Array Round #533 (Div. 2) 【DP】
一.题面 链接 二.分析 关于这题,两个点. 第一个点,是需要能够分析出$[L,R]$区间的3的余数的个数. 首先,可以得到,$[L,R]$区间内共有$(R-L+1)$个数. 设定余数为0,1,2的为 ...
- AIM Tech Round (Div. 2) D. Array GCD dp
D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...
- 北邮校赛 I. Beautiful Array(DP)
I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...
- hdu-5653 Bomber Man wants to bomb an Array.(区间dp)
题目链接: Bomber Man wants to bomb an Array. Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65 ...
随机推荐
- 【微服务No.1】Consul服务发现在windows下简单使用
基本介绍: 安装: 下载地址:https://www.consul.io/downloads.html 运行: consul agent -dev 显示这个界面说明已经开启成功. 页面显示: 然后访问 ...
- IIS Tomcat共享80端口
为什么有这种需求, 原因是这样的, 公司有一个Java的web项目,在另一台服务器A上,最近老板一时兴起,想把他合并到这台稳定点的服务器B上,服务器B上使用IIS来寄宿asp.net 网站, 怎么办呢 ...
- C#基础知识总结(二)
摘要 第二篇主要讲:变量.连接符占位符等.转义字符.数据的计算.数据的转换.try-catch的简单熟悉.复合运算符和自加自减 一.变量 1.数据存储在内存中:内存叫做RAM,内存被分隔为一小格一小格 ...
- 从零开始学安全(十五)●DHCP服务
DHCP,全名为:Dynamic Host Configuration Protocol,动态主机配置协议,它是一种基于UDP的局域网协议,其作用主要有:给主机自动分配IP地址,管理员通过该协议管理内 ...
- 从零开始学安全(十)●TCP/IP协议栈
局域网靠mac 地址通信
- c# 溢出上下文检测
对于类型转换是否溢出可以用 checked和unchecked运算符 在unchecked上下文中会忽略溢出 在checked 会抛出异常 ; byte sb; sb = unchecked((byt ...
- 【Redis】2、CentOS 7 上安装 redis3.2.3安装与配置
一.redis源码安装 [更正]现在最新稳定的版本已经到了3.2.8 截至到2016.8.11,redis最新稳定版本为3.2.3.本篇文章我们就以此版本为基础,进行相关的讲解. 下载redis源码, ...
- Integer Game(UVA11489)3的倍数
K - Integer Game Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pr ...
- Laravel 系列入门教程(五)【最适合中国人的 Laravel 教程】
本文是本系列教程的完结篇,我们将一起给 Article 加入评论功能,让游客在前台页面可以查看.提交.回复评论,并完成后台评论管理功能,可以删除.编辑评论.Article 和评论将使用 Laravel ...
- MVC模式-----struts2框架
MVC模式-----struts2框架 一.struts MVC模式 1.概述 MVC是模型(model)---视图model(view)---控制器(control)的缩写,是一种用于将逻辑.数据和 ...