【CodeForces - 1105C】Ayoub and Lost Array(线性计数dp)

题干:

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

2 1 3

Output

3

Input

3 2 2

Output

1

Input

9 9 99

Output

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

解题报告:

   dp[i][j]表示选择i个数可以组成模数为j的方案数。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
const ll mod = 1e9+7;
int n,l,r;
ll dp[MAX][3],num[3];
int main()
{cin>>n>>l>>r;ll tmp = (r-l)/3;num[0] = r/3 - (l-1)/3;num[1] = (r+2)/3 - (l+1)/3;num[2] = (r+1)/3 - (l)/3;dp[0][0]=1;for(int i = 1; i<=n; i++) {for(int j = 0; j<3; j++) {for(int k = 0; k<3; k++) {dp[i][j] += dp[i-1][k]*num[(j+3-k)%3];}dp[i][j]%=mod;}}	printf("%lld\n",dp[n][0]);return 0 ;
}

也可以直接dp[1][0,1,2]都给初始化好。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440686.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【牛客 - 373C】抓捕盗窃犯(连通图,思维,dfs 或 并查集)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/373/C 来源&#xff1a;牛客网 Q市发生了一起特大盗窃案。这起盗窃案是由多名盗窃犯联合实施的,你要做的就是尽可能多的抓捕盗窃犯。 已知盗窃犯分布于 N N个地点,以及第 i i个地点初始有 ai ai名盗…

android取消自动调试模式吗,Android进入调试模式的三种技巧

8种机械键盘轴体对比本人程序员&#xff0c;要买一个写代码的键盘&#xff0c;请问红轴和茶轴怎么选&#xff1f;Android开发过程中难免会遇到各种问题&#xff0c;通常我们会通过打印Log日志或者Debug模式来分析问题。这里介绍下Android程序进入到Debug的多种方式&#xff0c;…

IMX6怎么移植最新Android,[IMX6Q][Android5.1]移植筆記 --- 無法掛載system文件系統

platform: imx6qos: Android5.1branch: l5.1.1_2.1.0-ga編譯好system image之后開機提示如下log&#xff0c;注意紅色部分:Freeing unused kernel memory: 432K (c0be3000 - c0c4f000)usb 1-1: USB disconnect, device number 2Console: switching to colour dummy device 80x3…

【牛客 - 373A】翻硬币问题(博弈,结论,分析)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/373/A 来源&#xff1a;牛客网 Alice和Bob正在玩一个很经典的游戏。 有 n n个硬币初始时全部正面朝上&#xff0c;每一轮Alice必须选择其中任意的恰好 m m枚硬币并将它们全部翻转&#xff0c;如果若…

opera android 7,Opera迷你浏览器 Opera Mini 7

包名&#xff1a;com.opera.mini.android全新的界面Opera Mini 6在所有地方都有了全新的形象.新的设计、新的皮肤,还有新的缩放和跳转按键,这都让Opera Mini 6变得更加好用分享功能Opera Mini 6中你可以将感兴趣的内容分享到你所在社交平台中去触屏的双指缩放这次Opera也支持触…

【POJ - 1456】Supermarket (贪心,优先队列 或并查集)

题干&#xff1a; A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precis…

【CodeForces - 558C】Amr and Chemistry(位运算,bfs,计数,思维,tricks)

题干&#xff1a; Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ailiters. For this experiment, Amr has to mix all th…

axure 转换为html,AxureRP教程AxureRP如何生成HTML文件

1.正常打开一份已经设计好的RP&#xff0c;如下截图所示&#xff1a;2.点击上方菜单的“发布”按钮&#xff0c;在弹出的选项中单击“生成HTML文件”&#xff0c;详细操作如下图标红位置。3.在弹出的新窗口中&#xff0c;可以设定HTML文件保存的文件夹位置&#xff0c;这个位置…

【牛客 - 373B】666RPG(线性计数dp)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/373/B 来源&#xff1a;牛客网 在欧美&#xff0c;“666”是个令人极其厌恶和忌讳的数&#xff0c;被称为“野兽数”。 相传&#xff0c;尼禄&#xff0c;这位历史上以暴君著称的古罗马皇帝&#xff0…

我家云刷android系统教程,我家云刷机教程——小白详细版(篇二)

#大男孩的快乐#征稿活动火热进行中。只要投稿就有50金币等你拿&#xff0c;更有三千元乐高大奖与达人Z计划专属权益等待优秀的你~>活动详情戳这里<前两天发了一篇我家云的刷机教程&#xff0c;没想到大家这么有兴趣&#xff0c;讨论的异常激烈。看了大家的评论才发现之前…

【Loj - 515】贪心只能过样例(暴力,或01背包 + bitset)

题干&#xff1a; 题目描述 输入格式 第一行一个数 n。 然后 n 行&#xff0c;每行两个数表示 ai​,bi​。 输出格式 输出一行一个数表示答案。 样例 样例输入 5 1 2 2 3 3 4 4 5 5 6 样例输出 26 数据范围与提示 解题报告&#xff1a; 注意到要求统计种类数&#xf…

html5文件域的自动获取,HTML5 文件域+FileReader 读取文件(一)

在HTML5以前&#xff0c;HTML的文件上传域的功能具有很大的局限性&#xff0c;这种局限性主要体现在如下两点&#xff1a;每次只能选择一个文件进行上传客户端代码只能获取被上传文件的文件路径&#xff0c;无法访问实际的文件内容一、FileList对象和File对象HTML5为typefile 的…

计算几何 模板

计算几何模板&#xff1a; #include<iostream> #include<algorithm> #include<queue> #include<cstdio> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #d…

html中如何让三个方块并排,html – 并排设置两个div,然后设置第三个div

我如何并排设置两个div,而下面的第三个div设置为这样.我当前的代码如下所示,将div放在name div之后Name6:30 PMNoteCSS&#xff1a;#contact_table_data {width:inherit;height:inherit;background-color:#99cc33;max-width:400px;}#info_div_name {width:auto;height:auto;pad…

【ZOJ - 4019】Schrödinger's Knapsack (dp,背包,贪心,组内贪心组间dp)

题干&#xff1a; 有两种物品&#xff0c;k分别为k1&#xff0c;k2&#xff0c;有大小各不一的这两种物品若干&#xff0c;放入容量为c的背包中&#xff0c;能获得求最大的值。放的顺序会影响结果。每次放入一物品&#xff0c;其获得的值都可以用vkr计算&#xff0c;r表示放入…

html 闪烁字,HTML最简单的文字闪烁代码

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼Titlekeyframes blink{0%{opacity: 1;}50%{opacity: 1;}50.01%{opacity: 0;}100%{opacity: 0;}}-webkit-keyframes blink {0% { opacity: 1; }50% { opacity: 1; }50.01% { opacity: 0; }100% { opacity: 0; }}-moz-keyframes blin…

【ZOJ - 4020 】Traffic Light (bfs,分层图)

题干&#xff1a; n*m矩阵a.若a[i][j]1则可以往左右走,若a[i][j]0 则可以往上下走. 每一秒可以按上述规则移动,并且每秒钟矩阵所有的值翻转。 n*m<1e5.问从(sx,sy)到(tx,ty)的最短时间. 解题报告&#xff1a; 这题因为不带权值所以不需要考虑Dijkstra&#xff0c;可以根据…

在计算机应用中mis,在计算机的应用中,“MIS”表示

阅读下列材料&#xff0c;回答有关问题&#xff1a;地理信息系统(GIS)&#xff0c;也称作地理资讯系统&#xff0c;是一门综合性学科&#xff0c;已经广泛地应用在不同的领域&#xff0c;是用于输入、存储、查询、分析和显示地理数据的计算机系统。GIS属于信息系统的一类&#…

【牛客 - 369C】小A与欧拉路(bfs树的直径)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/369/C 来源&#xff1a;牛客网 小A给你了一棵树&#xff0c;对于这棵树上的每一条边&#xff0c;你都可以将它复制任意&#xff08;可以为0&#xff09;次&#xff08;即在这条边连接的两个点之间再…

html loader的作用,webpack认识loader的作用

举例&#xff1a;如果希望在.html文件中使用style.css样式&#xff0c;我们以前只学习过一种方式&#xff1a;直接在.html中通过link的方式来引入 &#xff0c;这是传统的做法&#xff0c;在webpack语境下&#xff0c;我们将选择一条不同的道路&#xff1a;在js文件中引入了css…