CF1105C Ayoub and Lost Array 题意:一个整数数组,满足: 1. 长度为n 2. 所有元素都在[l, r]范围内 3. 所有元素的和能被3整除给出n, l, r (1 ≤ n ≤ 2*10^5,1 ≤ l ≤ r ≤ 10^9)请找出符合条件的数组的个数,答案对 10^9 + 7取模 首先我们要处理出[l, r]中对3取模得结果分别为0,1,2的数的个数,在一个合乎要求的数组中,结果为1和2的数的个数必然一样,由此就可以很方便地得到所有可能的组合的个数.但新的问题来了,…
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 a…
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output Ayoub had an array aaa of integers of size nnn and this array had two interesting properties: All the integers in the array were between…
传送门:http://codeforces.com/contest/1105/problem/C 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…
链接 [https://codeforces.com/contest/1105/problem/C] 题意 给你n,表示数组长度,元素的值是l到r,问有多少种方案使得所有元素和整除3 分析 思维dp,看代码吧 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const ll mod=1e9+7; const int N=2e5+10; ll dp[N][3];//dp[i][j]表示l,r这个区间内i个数…
<题目链接> 题目大意: 有一个长度为 n 的数列的未知数列,数列的每一个数的值都在区间 [l,r]  的范围内.现在问你能够构成多少个这样的数组,使得数组内的所有数的和能够被 3 整除. 解题分析: 类似于这种数据量大的计数问题,要不就是数学推公式,要不就是dp. 根据所有数之和能被3整除的性质,我们将所有数用%3的余数表示,推出状态转移方程:$$ dp[i][j+k]=dp[i-1][j]*num[k]  $$ $dp[i][j]$表示:前$i$项之和余$j$的方案数. 这篇博客讲解的比较…
(又是被队友带着上分的一场--) 题目链接:http://codeforces.com/contest/1105/problem/C 题目大意:给你n,l,r.每一个数都是在l,r范围之内,然后问你这n个数形成的序列能够被3整除. 具体思路:我们先计算出l,r区间内整除3之后是0的个数,是1的个数,是2的个数,然后我们从第一位循环到第n位,第i位之前余数是0的情况等于前一位余数是1的情况*(l到r区间内余数是2的情况)+前一位余数是0的情况*(l到r区间内余数是0的情况)+前一位余数是2的情况*…
做法 \(f_{i,0}\)表示以\(i\)结尾未操作时的最大值 \(f_{i,1}\)表示以\(i\)结尾正在操作时的最大值 \(f_{i,2}\)表示以\(i\)结尾已结束操作时的最大值 Code #include<bits/stdc++.h> typedef long long LL; const int maxn=1e6+9; LL ans,n,x; LL a[maxn],f[maxn][3]; int main(){ std::cin>>n>>x; for(L…
一.题面 链接 二.分析 关于这题,两个点. 第一个点,是需要能够分析出$[L,R]$区间的3的余数的个数. 首先,可以得到,$[L,R]$区间内共有$(R-L+1)$个数. 设定余数为0,1,2的为一组,那么1,2,0和2,0,1也是一组.那么可以肯定能得到$(R-L+1)/3$组. 那么还余下了$(R-L+1)%3$个数.这里就需要考虑从$L$开始往右移$(R-L+1)%3$个数,分析这几个数的余数即可.因为这几个数后的数肯定是能分成3个一组的. 第二个点,用DP的思维去求解. 区间内的数能…
链接: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>…