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

dp

好题

*(if 满足条件)

满足条件 *1

不满足条件 *0

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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <string>
  6. #include <algorithm>
  7. #include <iostream>
  8. using namespace std;
  9. #define ll long long
  10.  
  11. const double eps=1e-;
  12. const ll inf=1e9;
  13. const ll mod=1e9+;
  14. const int maxn=1e6+;
  15.  
  16. /*
  17. dp题
  18. 检查:
  19. 1.认真检查公式
  20. 2.认真检查代码
  21. 3.造一个规模适中的数据
  22. 手动推导
  23. 对应程序的结果
  24. 判断是否相同
  25. */
  26.  
  27. ///+1 20->21 2->3
  28. ///0->-1 前面加一个辅助数组,这个数组里的所有元素数值为0
  29. ///x1*y1+x2*y2+x3*y3+...x20*y20 有可能会超long long, 所以所有乘法运算后面都加%mod
  30. ///1e18*k k<=9
  31. int f[maxn][21][3],v[21][3];
  32.  
  33. int main()
  34. {
  35. int n,two,three,i,j,k;
  36. scanf("%d",&n);
  37. two=log(n+eps)/log();///+eps
  38. three=(1.0*n/(<<two)>=1.5);
  39. for (i=;i<=two;i++)
  40. for (j=;j<=three;j++)
  41. v[i][j]=n/((<<i)*(j==?:));
  42.  
  43. f[][two][]=;
  44. if (three==)
  45. f[][two-][]=;
  46. for (i=;i<=n;i++)
  47. for (j=;j<=two;j++)
  48. for (k=;k<=three;k++)
  49. ///乘1ll,最后强制转换long long 转 int
  50. 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;
  51. printf("%d",f[n][][]);
  52. return ;
  53. }

推荐比如说这个xiongdi的代码

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

超内存的代码

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <string>
  6. #include <algorithm>
  7. #include <iostream>
  8. using namespace std;
  9. #define ll long long
  10.  
  11. const double eps=1e-;
  12. const ll inf=1e9;
  13. const ll mod=1e9+;
  14. const int maxn=1e6+;
  15.  
  16. /*
  17. dp题
  18. 检查:
  19. 1.认真检查公式
  20. 2.认真检查代码
  21. 3.造一个规模适中的数据
  22. 手动推导
  23. 对应程序的结果
  24. 判断是否相同
  25. */
  26.  
  27. ///+1 20->21 2->3
  28. ///0->-1 前面加一个辅助数组,这个数组里的所有元素数值为0
  29. ///x1*y1+x2*y2+x3*y3+...x20*y20 有可能会超long long, 所以所有乘法运算后面都加%mod
  30. ///1e18*k k<=9
  31. ll f[maxn][21][3],v[21][3];
  32.  
  33. int main()
  34. {
  35. int n,two,three,i,j,k;
  36. scanf("%d",&n);
  37. two=log(n+eps)/log();///+eps
  38. three=(1.0*n/(<<two)>=1.5);
  39. for (i=;i<=two;i++)
  40. for (j=;j<=three;j++)
  41. v[i][j]=n/((<<i)*(j==?:));
  42.  
  43. f[][two][]=;
  44. if (three==)
  45. f[][two-][]=;
  46. for (i=;i<=n;i++)
  47. for (j=;j<=two;j++)
  48. for (k=;k<=three;k++)
  49. 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;
  50.  
  51. printf("%lld",f[n][][]);
  52. return ;
  53. }

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. Html5介绍及新增标签

    什么是 HTML5? HTML5 将成为 HTML.XHTML 以及 HTML DOM 的新标准. HTML 的上一个版本诞生于 1999 年.自从那以后,Web 世界已经经历了巨变. HTML5 仍 ...

  2. mavenFailed to execute goal org.apache.maven.plugins:maven-surefire-plugin解决方法

    在项目上右键==>属性==>java构建路径==>源代码,然后把几个文件夹全部删除,然后再添加文件夹中把它们从新添加,然后再maven intall,部署.

  3. Nginx+Keepalived高可用集群应用实践

    Nginx+Keepalived高可用集群应用实践 1.Keepalived高可用软件 1.1 Keepalived服务的三个重要功能 1.1.1管理LVS负载均衡软件 早期的LVS软件,需要通过命令 ...

  4. 【LeetCode】二分

    [475] Heaters [Easy] 给你一排房子,一排加热器.找到能warm所有房子的最小加热器半径. 思路就是对于每个房子,找离它最近的左右两台heater, 分别求距离.温暖这个房子的hea ...

  5. 路由网关--spring cloud zuul

    路由网关--spring boot Zuul 1.为什么需要Zuul? Zuul Ribbon 以及 Eureka 相结合,可以实现智能路由和负载均衡的功能, Zuul 能够将请求流量按某种策略分发到 ...

  6. vue 重定向

    //重定向 { path: '/*', component: Home}

  7. JavaScript事件绑定的常见方式

    在Javascript中,事件绑定一共有3种方式: ① 行内绑定 ② 动态绑定 ③ 事件监听 原文: https://mbd.baidu.com/newspage/data/landingsuper? ...

  8. JavaScript常见设计模式梳理

    单例模式 单例模式,顾名思义就是保证每个类都只有一个实例对象. 其实现思路很简单,先判断实例是否存在,如果不存在则创建新的实例返回,如果存在则直接返回该实例. 策略模式 策略模式可以理解为:封装多个可 ...

  9. ToDoList 增删改查

    ToDoList 主要功能 增加数据 删除数据 修改数据 查寻数据渲染页面 1 . HTML页面 <!DOCTYPE html> <html lang="en"& ...

  10. delphi 文件操作(信息获取)

    delphi获取Exe文件版本信息的函数 Type TFileVersionInfo = Record FixedInfo:TVSFixedFileInfo; {版本信息} CompanyName:S ...