https://codeforces.com/contest/1174/problem/E

dp

好题

*(if 满足条件)

满足条件 *1

不满足条件 *0

///这代码虽然写着方便,但是常数有点大

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e6+; /*
dp题
检查:
1.认真检查公式
2.认真检查代码
3.造一个规模适中的数据
手动推导
对应程序的结果
判断是否相同
*/ ///+1 20->21 2->3
///0->-1 前面加一个辅助数组,这个数组里的所有元素数值为0
///x1*y1+x2*y2+x3*y3+...x20*y20 有可能会超long long, 所以所有乘法运算后面都加%mod
///1e18*k k<=9
int f[maxn][21][3],v[21][3]; int main()
{
int n,two,three,i,j,k;
scanf("%d",&n);
two=log(n+eps)/log();///+eps
three=(1.0*n/(<<two)>=1.5);
for (i=;i<=two;i++)
for (j=;j<=three;j++)
v[i][j]=n/((<<i)*(j==?:)); f[][two][]=;
if (three==)
f[][two-][]=;
for (i=;i<=n;i++)
for (j=;j<=two;j++)
for (k=;k<=three;k++)
///乘1ll,最后强制转换long long 转 int
f[i][j][k]=( 1ll*f[i-][j][k]*(v[j][k]-(i-))*((v[j][k]-(i-))>=)%mod + 1ll*f[i-][j+][k]*(v[j][k]-v[j+][k])*(j!=two)%mod + 1ll*f[i-][j][k+]*(v[j][k]-v[j][k+])*(k!=three)%mod )%mod;
printf("%d",f[n][][]);
return ;
}

推荐比如说这个xiongdi的代码

https://codeforces.com/contest/1174/submission/56391704

超内存的代码

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e6+; /*
dp题
检查:
1.认真检查公式
2.认真检查代码
3.造一个规模适中的数据
手动推导
对应程序的结果
判断是否相同
*/ ///+1 20->21 2->3
///0->-1 前面加一个辅助数组,这个数组里的所有元素数值为0
///x1*y1+x2*y2+x3*y3+...x20*y20 有可能会超long long, 所以所有乘法运算后面都加%mod
///1e18*k k<=9
ll f[maxn][21][3],v[21][3]; int main()
{
int n,two,three,i,j,k;
scanf("%d",&n);
two=log(n+eps)/log();///+eps
three=(1.0*n/(<<two)>=1.5);
for (i=;i<=two;i++)
for (j=;j<=three;j++)
v[i][j]=n/((<<i)*(j==?:)); f[][two][]=;
if (three==)
f[][two-][]=;
for (i=;i<=n;i++)
for (j=;j<=two;j++)
for (k=;k<=three;k++)
f[i][j][k]=( f[i-][j][k]*(v[j][k]-(i-))*((v[j][k]-(i-))>=)%mod + f[i-][j+][k]*(v[j][k]-v[j+][k])*(j!=two)%mod + f[i-][j][k+]*(v[j][k]-v[j][k+])*(k!=three)%mod )%mod; printf("%lld",f[n][][]);
return ;
}

Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem的更多相关文章

  1. Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem

    链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...

  2. Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem

    E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...

  3. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  4. Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person

    链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...

  5. Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos

    链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...

  6. Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale

    后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...

  7. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)

    参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...

  8. Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学

    题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可 ...

  9. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)

    题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...

随机推荐

  1. TCP建立连接的三次握手和释放连接的四次挥手

    TCP建立连接时,为什么要进行三次握手? 举个打电话的例子: A : 你好我是A,你听得到我在说话吗 B : 听到了,我是B,你听到我在说话吗 A : 嗯,听到了 建立连接,开始聊天! 第一次握手 第 ...

  2. 2019计蒜之道初赛第3场-阿里巴巴协助征战SARS 费马小定理降幂

    题目链接:https://nanti.jisuanke.com/t/38352 发现规律之后就是算ans=2^(n-1)+4^(n-1).但是注意到n十分大是一个长度为1e5的数字.要想办法降幂. 我 ...

  3. Codeforces 1111E DP + 树状数组 + LCA + dfs序

    题意:给你一颗树,有q次询问,每次询问给你若干个点,这些点可以最多分出m组,每组要满足两个条件:1:每组至少一个点,2:组内的点不能是组内其它点的祖先,问这样的分组能有多少个? 思路:https:// ...

  4. springboot集成使用rabbitmq笔记(3.基本过程)

    使用rabbitmq笔记一 使用rabbitmq笔记二 使用rabbitmq笔记三 1.AMQP协议 AMQP 0-9-1的工作过程如下图:消息(message)被发布者(publisher)发送给交 ...

  5. vue-cli构建的项目中请求代理与项目打包

    vue-cli构建的项目中,生产模式下的打包路径.与生产模式下的请求代理简单示意

  6. DNS稳定保障系列1--服务双保障“辅助DNS”产品介绍

    背景 2016 年 10 月 21 日,DNS 服务商 dyn 的服务器遭遇黑客大流量的 ddos 攻击,使得美国大量互联网公司如 twitter,github等都出现解析失败,无法提供服务.如下图可 ...

  7. sql 数据库

    在关系数据库中,最常用的操作就是查询.直线电机推杆 准备数据 为了便于讲解和练习,我们先准备好了一个students表和一个classes表,它们的结构和数据如下: students表存储了学生信息: ...

  8. PHP ftp_fget() 函数

    定义和用法 ftp_fget() 函数从 FTP 服务器上下载一个文件并保存到本地一个已经打开的文件中. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_fget(ftp ...

  9. 数学思维——cf351A

    把每个值的各种贡献算一下即可 /* ai的小数部分为xi,向下取整对答案贡献为xi 向上取整对答案的贡献是xi-1,如果这个数是0,那么对答案的贡献是xi,即如果0向上取整就可以免去-1 然后sum{ ...

  10. 管理员技术(五): 配置文档的访问权限、 配置附加权限、绑定到LDAP验证服务、配置LDAP家目录漫游

    一.配置文档的访问权限 问题: 本例要求将文件 /etc/fstab 拷贝为 /var/tmp/fstab,并调整文件 /var/tmp/fstab的权限,满足以下要求: 1>  此文件的拥有者 ...