题干:

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]都给初始化好。

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

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

    题干: 链接:https://ac.nowcoder.com/acm/contest/373/B 来源:牛客网 在欧美,"666"是个令人极其厌恶和忌讳的数,被称为"野兽 ...

  2. 【递推】Ayoub and Lost Array

    题目:Ayoub had an array aa of integers of size nn and this array had two interesting properties: All t ...

  3. CodeForces - 1312E Array Shrinking(区间dp)(通俗易懂)

    CodeForces - 1312E Array Shrinking(区间dp) 题目链接: 没做出来,看了一下别人的题解,才A掉.但网上没发现一篇讲得比较易懂的题解,所以就准备写一篇再加上我自己的理 ...

  4. dp2:线性dp、区间dp、计数dp.

    线性dp   动态规划时间复杂度分析,状态数目与状态转移次数相乘. 数字三角形 数字三角形 以集合的观点考虑dp问题. #include<iostream> #include<cst ...

  5. UVA 10564 计数DP

    也是经典的计数DP题,想练练手,故意不写记忆化搜索,改成递推,还是成功了嘞...不过很遗憾一开始WA了,原来是因为判断结束条件写个 n或s为0,应该要一起为0的,搞的我以为自己递推写挫了,又改了一下, ...

  6. Sumsets POJ - 2229(计数dp)

    题意: 给一个数,是集合的总数和,集合元素只能为2的次幂数,问这样的集合有多少? 题目: Farmer John commanded his cows to search for different ...

  7. CSPS 2019 Day2 T1 Emiya 家今天的饭(容斥 + 计数 dp)

    Description 给定一个 n×mn \times mn×m 的矩阵,每一行最多选一个数,每一列可以选若干个数,但是每一列选的数不能超总数的一半.求有多少个不同的方案数. Solution 容斥 ...

  8. Codeforces Round 722C:Destroying Array(离线)

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. 组合计数 ---- Codeforces 737C Div2 C. Moamen and XOR [多阶段决策计数dp]

    题目链接 题目大意: 有nnn个数.每次数范围是[0,2k]∣k∈[0,3e5][0,2^k]|k\in[0,3e5][0,2k]∣k∈[0,3e5] 问你有多少种情况这nnn个数的与大于等于异或 首 ...

最新文章

  1. unity3d-----Collider 组件参考
  2. 你想要的宏基因组-微生物组知识全在这(1802)
  3. Python中函数为什么可以当做参数使用?
  4. 《LeetCode力扣练习》剑指 Offer 09. 用两个栈实现队列 Java
  5. mysql server5.0使用_sco openserver 5.0.5安装使用mysql4.0.21的方法Windows系统 -电脑资料...
  6. c#中关于协变性和逆变性(又叫抗变)帮助理解
  7. 05-传统开发模式DAO
  8. HTML5 —— 属性
  9. win11如何显示所有应用图标 Windows11显示所有应用图标的设置方法
  10. 手机android系统界面,Android 4.0系统,界面很原生
  11. npm ERR! nested aliases not supported 报错原因
  12. NAIPC2018-K-Zoning Houses
  13. 永倍达商城:以新技术、新业态、新模式电商服务社会
  14. 二次型化标准形的三种方法
  15. “孙宇晨们”眼中的区块链,并非国家提倡的区块链
  16. MATLAB2018版本怎么手动安装硬件安装包
  17. windows找不到文件,如何解决。
  18. 【读书笔记】 玩转虚拟机基于Vmware+Windows 虚拟化技术
  19. 六万+字带你了解数据库---mysql--JDBC-Redis--MongoDB
  20. 直播电商软件开发,实现窗体抖动

热门文章

  1. vs2010 sp1 安装 Silverlight4_Tools 提示 错误 解决办法
  2. SQL 取n到m条记录
  3. 知识图谱需要解决的问题
  4. 15. 3Sum-数组
  5. [dp]leetcode 746. Min Cost Climbing Stairs
  6. Levko and Permutation CodeForces - 361B 思维 数论
  7. HDU-3998 Sequence LIS统计
  8. POJ-3624 Charm Bracelet dp
  9. 平面设计中的网格系统pdf_深入浅出,带你认识网格系统与版式设计
  10. 提高电脑反应速度_设计师笔记本电脑推荐——视觉系ThinkBook 15p创造本