【hdoj_2079】选课时间(母函数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2079
此题采用母函数的知识求解,套用母函数模板即可:
http://blog.csdn.net/ten_sory/article/details/59483762
C++代码如下:
- #include<iostream>
- using namespace std;
- int main()
- {
- int T,i,j,m;
- cin >> T;
- while(T--)
- {
- int MAX,k;
- cin >> MAX >> k;
- int *v = new int[k+1];
- int *e = new int[k+1];
- for(i=1;i<=k;i++)
- cin >> v[i] >> e[i];
- int *a = new int[MAX+1];
- int *b = new int[MAX+1];
- for(i=0;i<=MAX;i++)
- {
- a[i] = 0;
- b[i] = 0;
- }
- a[0] = 1;
- for(i=1;i<=k;i++)
- {
- for(j=0;j<=e[i] && j*v[i]<=MAX;j++)
- for(m=0;m+j*v[i]<=MAX;m++)
- b[m+j*v[i]]+=a[m];
- for(m=0;m<=MAX;m++)
- {
- a[m] = b[m];
- b[m] = 0;
- }
- }
- cout << a[MAX] << endl;
- }
- return 0;
- }
上述代码提交,可以通过.
【hdoj_2079】选课时间(母函数)的更多相关文章
- HDOJ 2079 选课时间(母函数)
选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU2079选课时间(母函数)
母函数的简单应用http://acm.hdu.edu.cn/showproblem.php?pid=2079 介绍见另一篇随笔HDU1028Ignatius and the Princess III( ...
- HDU 2079 选课时间(普通型 数量有限 母函数)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2079 选课时间(题目已修改,注意读题) Time Limit:1000MS Memory Li ...
- HDUOJ--2079选课时间(题目已修改,注意读题)
选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 2079 选课时间
hdu 2079 选课时间 题意:选的学分总和为n,并且学分为a的课有b种,总共有K(1<=k<=8)种学分不同的课,并且要选的学分最多为40:问选课方案有多少种?(学分相同的课即认为相同 ...
- hdu 2079 选课时间_母函数
题意:需要学够n学分,有k个情况(x学分,y个相同学分的课) 解法:套母函数模板 #include <iostream> #include<cstdio> using name ...
- 2079 ACM 选课时间 背包 或 母函数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2079 题意:同样的学分 ,有多少种组合数,注意同样学分,课程没有区别 思路:两种方法 背包 母函数 背包: ...
- hdu2079 选课时间(题目已修改,注意读题) 母函数
计算数的和的种类,母函数裸题 #include<stdio.h> #include<string.h> ],c2[],a,b; int main(){ int T; while ...
- HDU 2079 选课时间(母函数模板题)
链接:传送门 思路:母函数模板题 /************************************************************************* > Fil ...
随机推荐
- angularJS批量删除 品优购删除品牌(通用复选框批量选中删除解决思路)
思路: 一步:在点击复选框时维护变量数组 在js中定义一个数组变量, 给复选框添加点击动作, 在动作中判断当前复选框是否为选中状态(即点击后复选框的是否选中状态), 若为选中状态,则向数组中添加选中的 ...
- Ubuntu 14.04 64bit下Caffe + Cuda6.5/Cuda7.0 安装配置教程
http://www.embeddedlinux.org.cn/emb-linux/entry-level/201612/21-6005.html 随着深度学习快速发展的浪潮,许多有兴趣的工作者都转入 ...
- Codeforces Round #402 (Div. 2) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 2115: [Wc2011] Xor (线性基+dfs)
2115: [Wc2011] Xor Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 5714 Solved: 2420 题目链接:https://w ...
- Intervals ZOJ - 3953 (区间贪心)
Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that ...
- Bazinga 字符串HASH 这题不能裸HASH 要优化 毒瘤题
Ladies and gentlemen, please sit up straight. Don't tilt your head. I'm serious. For nn given string ...
- 题解【luogu4168 [Violet]蒲公英】
Description 给出一个长度为 \(n\) 序列 \(a\) ,\(m\) 次询问,每次询问区间 \([l,r]\) 里的众数(出现次数最多的数).若有多个,输出最小的. \(a_i \leq ...
- sublime text3常用快捷键
Ctrl+L 选择整行(按住-继续选择下行) Ctrl+KK 从光标处删除至行尾 Ctrl+Shift+K 删除整行 Ctrl+Shift+D 复制光标所在整行,插入在该行之前 Ctrl+J 合并行( ...
- MySql 利用函数 查询所有子节点
前提:mysql 函数 find_in_set(str,strlist), cast(value as type) 一.find_in_set(str,strlist):如果字符串str是在的 ...
- SPOJ AMR11E Distinct Primes 基础数论
Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger i ...