Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C
题意:
给n,l,r。
一个n长的数组每个位置可以填区间l-r的值。
有多少种填法,使得数组每个位置相加的和是3的倍数
思路:
赛后看代码都看不懂的题。
dp,
从1个数组扩展到n个数组,
dp[i][j]是加上第i个数组后,分别余0,1,2的个数。
余0则是,i-1余0*自己余0+(i-1余1*自己余2)+(i-1余2*自己余1)
剩下同理
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2*1e5+10;
const int MOD = 1e9+7;
LL dp[MAXN][3]; int main()
{
int n,l,r;
cin >> n >> l >> r;
dp[0][0] = 1,dp[0][1] = 0,dp[0][2] = 0;
int mod0 = r/3-(l-1)/3,mod1 = (r+2)/3-(l+1)/3,mod2 = (r+1)/3-(l)/3;
for (int i = 1;i<=n;i++)
{
dp[i][0] = (dp[i-1][0]*mod0%MOD+dp[i-1][1]*mod2%MOD+dp[i-1][2]*mod1%MOD)%MOD;
dp[i][1] = (dp[i-1][0]*mod1%MOD+dp[i-1][1]*mod0%MOD+dp[i-1][2]*mod2%MOD)%MOD;
dp[i][2] = (dp[i-1][0]*mod2%MOD+dp[i-1][1]*mod1%MOD+dp[i-1][2]*mod0%MOD)%MOD;
}
cout << dp[n][0] << endl; return 0;
}
Codeforces Round #533(Div. 2) C.Ayoub and Lost Array的更多相关文章
- 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 Round #533 (Div. 2) C. Ayoub and Lost Array(递推)
题意: 长为 n,由 l ~ r 中的数组成,其和模 3 为 0 的数组数目. 思路: dp[ i ][ j ] 为长为 i,模 3 为 j 的数组数目. #include <bits/stdc ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】
传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...
- Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
- Codeforces Round #533(Div. 2) B.Zuhair and Strings
链接:https://codeforces.com/contest/1105/problem/B 题意: 给一个字符串和k,连续k个相同的字符,可使等级x加1, 例:8 2 aaacaabb 则有aa ...
- Codeforces Round #533(Div. 2) A.Salem and Sticks
链接:https://codeforces.com/contest/1105/problem/A 题意: 给n个数,找到一个数t使i(1-n)∑|ai-t| 最小. ai-t 差距1 以内都满足 思路 ...
随机推荐
- css中IE判断语句 if !IE
1. <!–[if !IE]><!–> 除IE外都可识别 <!–<![endif]–> 2. <!–[if IE]> 所有的IE可识别 <! ...
- CentOS(Linux) - 安装软件笔记(一) - VPSMate(服务器可视化管理工具)安装
更多详情点击参考官网说明 vpsmate官方推荐centos版本为6.2 64位 使用 SSH 连接工具,如 PuTTY.XShell.SecureCRT 等,连接到您的 Linux 服务器. 执行以 ...
- 动态负载均衡(Nginx+Consul+UpSync)
Http动态负载均衡 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件, 因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upst ...
- 【小程序】bindconfirm点击小键盘触发事件、focus自动获取焦点
最近在写小程序,项目要求写一个搜索框,在进入页面时就触发input的事件,调出键盘,点小键上的搜索按钮 就触发搜索事件,分享一下. bindconfirm 是点击小键盘上的搜索按钮就触发要执行的方法 ...
- 网站流量统计之PV和UV
转自:http://blog.csdn.NET/webdesman/article/details/4062069 如果您是一个站长,或是一个SEO,您一定对于网站统计系统不会陌生,对于SEO新手来说 ...
- SVG-Android开源库——SVG生成Vector资源文件的编辑预览工具
Vector矢量图在Android项目中的应用越来越广泛,但是如果你想用Android Studio自带的工具将SVG图片转化成Vector资源文件却是相当麻烦,首先能支持的SVG规范较少,其次操作流 ...
- linux应用之nginx的安装及配置(centos)
Ubuntu/CentOS 系统上安装与配置Nginx 一.在线安装: Ubuntu:sudo apt-get install nginx CentOS: sudo yum install nginx ...
- 在SQL SERVER 2008中通过已有的数据库生成建库脚本
- ubuntu解决挂起后不能唤醒
安装 laptop-mode 如果你不缺认自已是否安装了laptop-mode-tools工具包,可以在终端中输入下列命令来确认是否安装. dpkg -l | grep laptop-mode-too ...
- 回味经典——uboot1.1.6 之 第一阶段
转自:http://blog.csdn.net/lizuobin2/article/details/52054293 最近打算移植一个比较新的 uboot 到开发板,回想起来上一次移植 uboot1. ...