codeforces 1195D2-Submarine in the Rybinsk Sea
传送门:QAQQAQ
题意:自己看
思路:就是一个类似于数位DP的东西。。。
统计a[i]数位分解的数在每一位出现的个数,即分两种讨论:
1.位数小于当前j,则j会出现在q+i,而且计算顺序互换会计算两遍
2.位数大于等于当前j,则j会出现在j*2-1或j*2
(比赛时光D1就调老半天,D2又太谨慎,结果E没时间做了)
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define m_k make_pair
const int inf=(int)(2e9);
const ll INF=(ll)(5e18);
const int N=;
const ll MOD=;
ll a[N][],d[N],ans=;
int n,len[N],t[];
ll dp[N][][];
int fd(ll x,int id)
{
int ret=;
while(x)
{
a[id][++ret]=x%;
x/=;
}
return ret;
}
int main()
{
memset(t,,sizeof(t));
memset(dp,,sizeof(dp));
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&d[i]);
}
sort(d+,d+n+);
for(int i=;i<=n;i++)
{
len[i]=fd(d[i],i);
t[len[i]]++;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=len[i];j++)
{
ll now=;
for(int pre=;pre<j;pre++)
{
dp[i][j][pre+j]+=t[pre]*;//前后两种都要考虑
now+=t[pre];
}
ll sum=n-now;
dp[i][j][j*]+=sum;
dp[i][j][j*-]+=sum;
}
}
ll ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++)
{
ll now=;
for(int k=;k<=;k++)
{
if(k>) now=now*%MOD;
ans=(ans+a[i][j]*dp[i][j][k]%MOD*now)%MOD;
}
}
}
printf("%lld\n",ans);
return ;
}
codeforces 1195D2-Submarine in the Rybinsk Sea的更多相关文章
- Codeforces - 1195D2 - Submarine in the Rybinsk Sea (hard edition) - 组合数学
https://codeforc.es/problemset/problem/1195/D2 很明显可以看出,任意一个长度为\(l_1\)的数串\(s_1\)和任意一个长度为\(l_2\)的数串\(s ...
- Codeforces - 1195D1 - Submarine in the Rybinsk Sea (easy edition) - 水题
https://codeforc.es/contest/1195/problem/D1 给\(n\)个等长的十进制数串,定义操作\(f(x,y)\)的结果是"从\(y\)的末尾开始一个一个交 ...
- Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】
一.题目 D2. Submarine in the Rybinsk Sea (hard edition) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...
- Codeforces Round #574 (Div. 2) D1. Submarine in the Rybinsk Sea (easy edition) 【计算贡献】
一.题目 D1. Submarine in the Rybinsk Sea (easy edition) 二.分析 简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的 ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- Codeforces Round #302 (Div. 2) B. Sea and Islands 构造
B. Sea and Islands Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/p ...
- Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...
- Codeforces Round #541 (Div. 2) A.Sea Battle
链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
- Codeforces Round #574 (Div. 2)
目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...
随机推荐
- 【POJ】1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 题意:n个城镇,m条路上能承载的最大重量.现在问你从1到n的最大承重量. 题解:spfa的变体. 假设当前1->当前点的承 ...
- POJ 1946 Cow Cycling
Cow Cycling Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2516 Accepted: 1396 Descr ...
- MySQL 08章_数据库设计
一. 关系模型与对象模型之间的对应关系 序号 关系模型:数据库 对象模型:java程序 1 数据表table 实体entity:特殊的java类 2 字段field 属性attribute/字段fie ...
- java 冒泡排序法、选择排序
1.冒泡排序 /* * 冒泡排序 * 外层控制循环多少趟,内层控制每一趟的循环次数 */ public class Test08 { public static void main(String[] ...
- JS对象 指定分隔符连接数组元素join() join()方法用于把数组中的所有元素放入一个字符串。元素是通过指定的分隔符进行分隔的。
指定分隔符连接数组元素join() join()方法用于把数组中的所有元素放入一个字符串.元素是通过指定的分隔符进行分隔的. 语法: arrayObject.join(分隔符) 参数说明: 注意:返回 ...
- overleaf 提交arXiv 不成功
从overleaf下载的PDF不能够直接提交给arXiv,但是可以在submit中选择导出下载压缩包,图片不能是png,最好是PDF 或者eps. 参考文献是bbl 文件,不是bib.
- 【模板篇】A* 寻路算法
上次在做k短路的时候说到了A*, 但是并没有仔细的研究A*寻路, 毕竟k短路中的A*也不怎么标准… A*寻路的过程网上还是有很多的, 讲得也很清楚, 不妨跟着里面的图示自己动手操作一下, 基本一遍就能 ...
- SpringBoot防止重复请求,重复表单提交超级简单的注解实现
1. 注解接口 /** * @description 防止表单重复提交注解 */@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHO ...
- 在Spring-boot中,为@Value注解添加从数据库读取properties支持
一般我们会把常用的属性放在工程的classpath文件夹中,以property,yaml或json的格式进行文件存储,便于Spring-boot在初始化时获取. @Value则是Spring一个非常有 ...
- Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)F3 - Lightsabers (hard)
题意:n个数字1-m,问取k个组成的set方案数 题解:假设某个数出现k次,那么生成函数为\(1+x+...+x^k\),那么假设第i个数出现ai次,结果就是\(\sum_{i=1}^m(1+x+.. ...