题目传送门:https://vjudge.net/problem/HDU-1028

思路:整数拆分构造母函数的模板题

  1 //#include<bits/stdc++.h>
2 #include<time.h>
3 #include <set>
4 #include <map>
5 #include <stack>
6 #include <cmath>
7 #include <queue>
8 #include <cstdio>
9 #include <string>
10 #include <vector>
11 #include <cstring>
12 #include <utility>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 #include <list>
17 using namespace std;
18 #define eps 1e-10
19 #define PI acos(-1.0)
20 #define lowbit(x) ((x)&(-x))
21 #define zero(x) (((x)>0?(x):-(x))<eps)
22 #define mem(s,n) memset(s,n,sizeof s);
23 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
24 typedef long long ll;
25 typedef unsigned long long ull;
26 const int maxn=1e3+5;
27 const int Inf=0x7f7f7f7f;
28 const ll Mod=999911659;
29 const int N=3e3+5;
30 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
31 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
32 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
33 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
34 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
35 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
36 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
37 int Abs(int n) {
38 return (n ^ (n >> 31)) - (n >> 31);
39 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
40 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
41 需要计算 n 和 -1 的补码,然后进行异或运算,
42 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
43 }
44 ll binpow(ll a, ll b,ll c) {
45 ll res = 1;
46 while (b > 0) {
47 if (b & 1) res = res * a%c;
48 a = a * a%c;
49 b >>= 1;
50 }
51 return res%c;
52 }
53 void extend_gcd(ll a,ll b,ll &x,ll &y)
54 {
55 if(b==0) {
56 x=1,y=0;
57 return;
58 }
59 extend_gcd(b,a%b,x,y);
60 ll tmp=x;
61 x=y;
62 y=tmp-(a/b)*y;
63 }
64 ll mod_inverse(ll a,ll m)
65 {
66 ll x,y;
67 extend_gcd(a,m,x,y);
68 return (m+x%m)%m;
69 }
70 ll eulor(ll x)
71 {
72 ll cnt=x;
73 ll ma=sqrt(x);
74 for(int i=2;i<=ma;i++)
75 {
76 if(x%i==0) cnt=cnt/i*(i-1);
77 while(x%i==0) x/=i;
78 }
79 if(x>1) cnt=cnt/x*(x-1);
80 return cnt;
81 }
82 int c1[maxn],c2[maxn];
83 int val[maxn];
84 int main()
85 {
86 ios
87 int n;
88 while(cin>>n)
89 {
90 for(int i=1;i<=n;i++) val[i]=i;
91 mem(c1,0);
92 mem(c2,0);
93 for(int i=0;i<=n;i++) c1[i]=1;
94 for(int i=2;i<=n;i++)
95 {
96 for(int j=0;j<=n;j++)
97 {
98 for(int k=0;k+j<=n;k+=val[i])
99 {
100 c2[j+k]+=c1[j];
101 }
102 }
103 for(int j=0;j<=n;j++)
104 {
105 c1[j]=c2[j];
106 c2[j]=0;
107 }
108 }
109 cout<<c1[n]<<endl;
110 }
111 return 0;
112 }

母函数详解:https://blog.csdn.net/baidu_23955875/article/details/42174965

Ignatius and the Princess III HDU - 1028的更多相关文章

  1. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  2. Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数

    HDU - 1028 step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1.临时区 temp初始化 为 0 step 2:遍历后续的n - 1 个 多项式 , ...

  3. hdu acm 1028 数字拆分Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  4. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  5. HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

  6. hdu 1028 Ignatius and the Princess III(DP)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. HDU 1028 整数拆分问题 Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  9. hdu 1028 Ignatius and the Princess III 母函数

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

随机推荐

  1. HDU2837 Calculation(指数循环节)题解

    题意: 已知\(f(0)=1,f(n)=(n\%10)^{f(n/10)}\),求\(f(n)\mod m\) 思路: 由扩展欧拉定理可知:当\(b>=m\)时,\(a^b\equiv a^{b ...

  2. 康托展开:对全排列的HASH和还原,判断搜索中的某个排列是否出现过

    题目:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2297 前置技能:(千万注意是 ...

  3. GitHub Actions in Action

    GitHub Actions in Action https://lab.github.com/githubtraining/github-actions:-hello-world https://g ...

  4. 如何在 macOS 上进行滚动截屏

    如何在 macOS 上进行滚动截屏 Shift-Command-5 https://support.apple.com/zh-cn/guide/mac-help/mh26782/mac demo Xn ...

  5. 移动端 750px UI 设计稿

    750px UI 设计稿 App 小程序 H5 rem & vh/vw 在移动端页面开发中,UI 一般会用750px(iphone 6)来出设计稿; 然后要求能够做到页面是自适应屏幕的,这种情 ...

  6. css delete line text & html del

    css delete line text & html del html <del>¥720</del> demo <span class="ticke ...

  7. Redis-第九章节-动态字符串

    目录 概述 SDS(动态字符串) SDS(动态字符串)与c语言字符串的区别 1.概述 String类型底层实现的简单动态字符串sds,是可以修改的字符串.它采用预分配冗余空间的方式来减少内存的频繁分配 ...

  8. 经典面试题:在浏览器地址栏输入一个 URL 后回车,背后发生了什么

    尽人事,听天命.博主东南大学硕士在读,热爱健身和篮球,乐于分享技术相关的所见所得,关注公众号 @ 飞天小牛肉,第一时间获取文章更新,成长的路上我们一起进步 本文已收录于 CS-Wiki(Gitee 官 ...

  9. HTTP 1.x 学习笔记 —— Web 性能权威指南

    HTTP 1.0的优化策略非常简单,就一句话:升级到HTTP 1.1.完了! 改进HTTP的性能是HTTP 1.1工作组的一个重要目标,后来这个版本也引入了大量增强性能的重要特性,其中一些大家比较熟知 ...

  10. ForkJoinPool大型图文现场(一阅到底 vs 直接收藏)

    知识回顾 并发工具类我们已经讲了很多,这些工具类的「目标」是让我们只关注任务本身,并且忽视线程间合作细节,简化了并发编程难度的同时,也增加了很多安全性.工具类的对使用者的「目标」虽然一致,但每一个工具 ...