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 以内都满足 思路 ...
随机推荐
- Discuz/X3.1去掉标题中的Powered by Discuz!以及解决首页标题后的"-"
虽然不提倡大家去掉版权信息,但是在实际操作的时候还是去掉,毕竟每个页面标题最后面出现”Powered by Discuz!“会显得页面标题比较冗长. 经过本人的实践,论坛里也有操作方法,不过那个操作方 ...
- IOS从背景图中取色
1. [代码][其他]代码 void *bitmapData; //内存空间的指针,该内存空间的大小等于图像使用RGB通道所占用的字节数. static CGContextRef Creat ...
- C3P0 配置
C3P0是一个开源的JDBC连接池. 在Spring中,C3P0的一些配置,介绍如下(只列了一部分,不是全部) <!-- c3p0连接池配置 --> <bean id="d ...
- 解决Spring MVC中文乱码
在web.xml中设置编码过滤器 <filter> <filter-name>characterEncodingFilter</filter-name> <f ...
- Nuget:Newtonsoft.Json
ylbtech-Nuget:Newtonsoft.Json 1.返回顶部 2.返回顶部 1,Serialize JSON Product product = new Product(); prod ...
- 【转】Cache Buffer Chain 第二篇
文章转自:http://m.bianceng.cn/database/Oracle/201407/42884.htm 测试环境:版本11gR2 SQL> select * from v$vers ...
- 查看Spring源码的方法
来自为知笔记(Wiz)
- java读取文件:二进制文件
FileWriter只能接受字符串形式的参数,也就是说只能把内容存到文本文件.相对于文本文件,采用二进制格式的文件存储更省空间 InputStream用于按字节从输入流读取数据.其中的int read ...
- 7、html的body内标签之图片及表格
一.image <a href="https://www.baidu.com" target="_blank"> <img src=" ...
- php破解防盗链技术
php破解防盗链技术 发送http请求 构造referer信息 在Http协议中,头信息里,有一个重要的选项: Referer Referer: 代表网页的来源,即上一页的地址 具体方法http.cl ...