[hdu1085]生成函数
题意:给a个1、b个2、c个5,求不能构成最小的数
思路: 先求1能构成的所有数,2能构成的所有数,5能构成的所有数,它们的方法数显然都是1,现在考虑把3者结合在一起,由于结果为和的形式,而又是循环加的,所以考虑用多项式来表示状态,然后进行两次卷积运算就行了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <vector> #include <ctime> #include <deque> #include <queue> #include <algorithm> #include <map> #include <cmath> using namespace std; #define X first #define Y second #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define fillchar(a, x) memset(a, x, sizeof(a)) typedef pair< int , int > pii; typedef long long ll; typedef unsigned long long ull; #ifndef ONLINE_JUDGE void RI(vector< int >&a, int n){a.resize(n); for ( int i=0;i<n;i++) scanf ( "%d" ,&a[i]);} void RI(){} void RI( int &X){ scanf ( "%d" ,&X);} template < typename ...R> void RI( int &f,R&...r){RI(f);RI(r...);} void RI( int *p, int *q){ int d=p<q?1:-1; while (p!=q){ scanf ( "%d" ,p);p+=d;}} void print(){cout<<endl;} template < typename T> void print( const T t){cout<<t<<endl;} template < typename F, typename ...R> void print( const F f, const R...r){cout<<f<< ", " ;print(r...);} template < typename T> void print(T*p, T*q){ int d=p<q?1:-1; while (p!=q){cout<<*p<< ", " ;p+=d;}cout<<endl;} #endif template < typename T> bool umax(T&a, const T&b){ return b<=a? false :(a=b, true );} template < typename T> bool umin(T&a, const T&b){ return b>=a? false :(a=b, true );} template < typename T> void V2A(T a[], const vector<T>&b){ for ( int i=0;i<b.size();i++)a[i]=b[i];} template < typename T> void A2V(vector<T>&a, const T b[]){ for ( int i=0;i<a.size();i++)a[i]=b[i];} const double PI = acos (-1.0); const int INF = 1e9 + 7; /* -------------------------------------------------------------------------------- */ int a[12345], b[12345]; int main() { #ifndef ONLINE_JUDGE freopen ( "in.txt" , "r" , stdin); //freopen("out.txt", "w", stdout); #endif // ONLINE_JUDGE int n1, n2, n3; while (cin >> n1 >> n2 >> n3, n1 + n2 + n3 > 0) { fillchar(a, 0); fillchar(b, 0); for ( int i = 0; i <= n1; i ++) { for ( int j = 0; j <= 2 * n2; j += 2) { a[i + j] ++; } } int sz = n1 + 2 * n2; for ( int i = 0; i <= sz; i ++) { for ( int j = 0; j <= 5 * n3; j += 5) { b[i + j] += a[i]; } } for ( int i = 0; ; i ++) { if (!b[i]) { cout << i << endl; break ; } } } return 0; } |
[hdu1085]生成函数的更多相关文章
- hdu1085 Holding Bin-Laden Captive!【生成函数】
列出生成函数的多项式之后暴力乘即可 #include<iostream> #include<cstdio> #include<cstring> using name ...
- [CodeForces - 712D]Memory and Scores (DP 或者 生成函数)
题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高. ( ...
- HDU 1171 Big Event in HDU --暴力+生成函数
题意:给n种房子,每种房子有一个值val和个数cnt,现在要把这些房子分成两部分,争取两部分总值相等,如果不能相等,让A>B,且A-B最小. 解法:先跑一次生成函数,c[n]表示组成总值为n的方 ...
- HDU 2189 悼念512汶川大地震遇难同胞――来生一起走 --生成函数
这题跟上两题也差不多. 把150以内的素数找出来,把素数的值看做硬币的面值,每个硬币的个数即ceil(150/prime[i]),因为再多也没用,最多组成n=150就行了,所以又回到了找硬币问题.用生 ...
- HDU 1085 Holding Bin-Laden Captive --生成函数第一题
生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...
- BZOJ3028 食物 (生成函数)
首先 1+x+x^2+x^3+...+x^∞=1/(1-x) 对于题目中的几种食物写出生成函数 (对于a*x^b , a表示方案数 x表示食物,b表示该种食物的个数) f(1)=1+x^2+x^4+. ...
- C# 条形码 生成函数 (Code 128 标准
C# 条形码 生成函数 (Code 128 标准参考:GB/T 18347-2001) 最近在做单据打印,发现客户要求用到条形码,在网上找了,发现只有一些条形码的标准,但打出来发现根本不能扫,还要加某 ...
- [原创]oracle 顺序号生成函数。仿Sequence
问题提出自项目中的老代码:一个Bill表,存储所有的表单信息,比如:员工入职单,离职单等等.(别喷,我知道要分多个表.但领导的意愿你是没办法违背的)表单的单据号是以四个字母+年月日+数字顺序号来表示. ...
- FFT与多项式、生成函数题目泛做
题目1 COGS 很强的乘法问题 高精度乘法用FFT加速 #include <cstdlib> #include <iostream> #include <algorit ...
随机推荐
- css: scroll-table
.scroll-table { table tbody { display: block; max-height: 120px; overflow-y: scroll; } table thead,t ...
- 在手机和电脑间双向加密传输文件 —— Windows 安装 Kde Connect
2020-04-27 作为 Kde 项目的一部分,Windows 用户可能很少知道它,但它确实存在,而且超棒. Kde Connect 简直了,现在我的手机和 Linux 主机以及 Win 本完全是一 ...
- thinkphp5.0.x
payload5.0.24 http://-----/index.php?s=index/think\app/invokefunction&function=call_user_func_ar ...
- curl的$post传递多维数组
php curl传数组的话只能传一维数组,如果想传多维数组:两个方法: 1.转换成json在传输 2. //通过curl模拟post的请求: function SendDataByCurl($url, ...
- sql语句-------重复时插入更新
ON DUPLICATE KEY UPDATE重复时插入更新 insert into user(id,username) value('231',"二人") on duplicat ...
- Task Scheduler API Error 80041318
https://stackoverflow.com/questions/42307917/task-scheduler-api-error-80041318/42462235#42462235 Hi ...
- #Week4 Logistic Regression
一.Classification 主要讨论二元分类. 线性回归处理分类问题显然不靠谱,所以采用逻辑回归. 二.Hypothesis Representation 假设函数变为\(h_\theta(x) ...
- Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) B. Homecoming
After a long party Petya decided to return home, but he turned out to be at the opposite end of the ...
- P2290 [HNOI2004]树的计数(bzoj1211)
洛谷P2290 [HNOI2004]树的计数 bzoj1211 [HNOI2004]树的计数 Description 一个有\(n\)个结点的树,设它的结点分别为\(v_1,v_2,\cdots, v ...
- python文件路径分隔符的详细分析
写了挺久的python,文件分隔符的掌握肯定是必须的,但是我之前写的都是不规范的文件路径分隔符,例如‘’C:\User\temp\python.txt’,一直都没有报过错.也不知为啥,今天查阅资料才知 ...