C. Ayoub and Lost Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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 .

Input

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.

Output

Print the remainder when dividing by 109+7109+7 the number of ways to restore the array.

Examples
Input

Copy
2 1 3
Output

Copy
3
Input

Copy
3 2 2
Output

Copy
1
Input

Copy
9 9 99
Output

Copy
711426616
Note

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的更多相关文章

  1. 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 ...

  2. Codeforces 1105C Ayoub and Lost Array (计数DP)

    <题目链接> 题目大意: 有一个长度为 n 的数列的未知数列,数列的每一个数的值都在区间 [l,r]  的范围内.现在问你能够构成多少个这样的数组,使得数组内的所有数的和能够被 3 整除. ...

  3. C. Ayoub and Lost Array(DP)

    (又是被队友带着上分的一场--) 题目链接:http://codeforces.com/contest/1105/problem/C 题目大意:给你n,l,r.每一个数都是在l,r范围之内,然后问你这 ...

  4. Codeforces 1105C: Ayoub and Lost Array(递推)

    time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...

  5. CF1105C Ayoub and Lost Array ——动态规划

    CF1105C Ayoub and Lost Array 题意:一个整数数组,满足: 1. 长度为n 2. 所有元素都在[l, r]范围内 3. 所有元素的和能被3整除给出n, l, r (1 ≤ n ...

  6. C. Ayoub and Lost Array Round #533 (Div. 2) 【DP】

    一.题面 链接 二.分析 关于这题,两个点. 第一个点,是需要能够分析出$[L,R]$区间的3的余数的个数. 首先,可以得到,$[L,R]$区间内共有$(R-L+1)$个数. 设定余数为0,1,2的为 ...

  7. 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 ...

  8. 北邮校赛 I. Beautiful Array(DP)

    I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...

  9. 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 ...

随机推荐

  1. mysql+mycat实现读写分离

    centos7       master slave mycat1.6 client 192.168.41.10 192.168.41.11 192.168.41.12 192.168.41.13 实 ...

  2. aspx 页面中 js 引用与页面后台的数据交互 --【 js 调后台】

    后台调用 js 方法 前台调用后台方法与变量:  后台被调用的方法必须是public 或 protected 后台被调用的方法必须是静态的static 方法一:通过WebService来实现 步骤: ...

  3. springMVC_04controller四种配置总结

    一.通过url对应bean,加粗部分为必须有的 <bean class=" org.springframework.web.servlet.handler.BeanNameUrlHan ...

  4. POST与GET的联系与区别

    是什么? GET与POST是在客户机和服务器之间进行请求-响应时,两种最常被用到的方法: GET-从指定的资源请求数据. POST-向指定的资源提交要被处理的数据. 所以我们从语义上就能看出两者最明显 ...

  5. Javascript 对象 - 日期对象

    日期对象 在JavaScript中提供了Data对象,用于处理和日期有关的内容.通过Data对象可以获取系统时间.设置时间等.Data对象也具有prototype和constructor属性. 1创建 ...

  6. Tomcat_记一次tomcatwar包应用简单部署过程

    记一次tomcat war包应用简单部署过程 by:授客 QQ:1033553122 1.  实践环境 Linux apache-tomcat-7.0.73 2.  实践步骤 # 解压tomcat压缩 ...

  7. Nginx http相关常用配置总结

    Nginx http相关常用配置总结   by:授客  QQ:1033553122   测试环境 nginx-1.10.0 client_max_body_size Syntax: client_ma ...

  8. Loadrunner 脚本开发-利用loadrunner开发Windows Sockets协议脚本

    脚本开发-利用loadrunner开发Windows Sockets协议脚本 by:授客 QQ:1033553122 欢迎加入软件性能测试交流QQ群:7156436 实践举例 Socket服务端简单实 ...

  9. 浅谈Kotlin(三):类

    浅谈Kotlin(一):简介及Android Studio中配置 浅谈Kotlin(二):基本类型.基本语法.代码风格 浅谈Kotlin(三):类 浅谈Kotlin(四):控制流 前言: 已经学习了前 ...

  10. Last Day in Autodesk

    今天是我的最后一天在Autodesk上海了,以后将不再折腾那么大的软件了,还是回到CG开发中捣鼓短小精悍的东西——我还将继续整理开源CG生产工具. Today is my last day in Au ...