题目:http://acm.hdu.edu.cn/showproblem.php?pid=2079

此题采用母函数的知识求解,套用母函数模板即可:

http://blog.csdn.net/ten_sory/article/details/59483762

C++代码如下:

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int T,i,j,m;
  7. cin >> T;
  8. while(T--)
  9. {
  10. int MAX,k;
  11. cin >> MAX >> k;
  12. int *v = new int[k+1];
  13. int *e = new int[k+1];
  14. for(i=1;i<=k;i++)
  15. cin >> v[i] >> e[i];
  16.  
  17. int *a = new int[MAX+1];
  18. int *b = new int[MAX+1];
  19. for(i=0;i<=MAX;i++)
  20. {
  21. a[i] = 0;
  22. b[i] = 0;
  23. }
  24. a[0] = 1;
  25.  
  26. for(i=1;i<=k;i++)
  27. {
  28. for(j=0;j<=e[i] && j*v[i]<=MAX;j++)
  29. for(m=0;m+j*v[i]<=MAX;m++)
  30. b[m+j*v[i]]+=a[m];
  31. for(m=0;m<=MAX;m++)
  32. {
  33. a[m] = b[m];
  34. b[m] = 0;
  35. }
  36. }
  37. cout << a[MAX] << endl;
  38. }
  39.  
  40. return 0;
  41. }

上述代码提交,可以通过.

【hdoj_2079】选课时间(母函数)的更多相关文章

  1. HDOJ 2079 选课时间(母函数)

    选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU2079选课时间(母函数)

    母函数的简单应用http://acm.hdu.edu.cn/showproblem.php?pid=2079 介绍见另一篇随笔HDU1028Ignatius and the Princess III( ...

  3. HDU 2079 选课时间(普通型 数量有限 母函数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2079 选课时间(题目已修改,注意读题) Time Limit:1000MS     Memory Li ...

  4. HDUOJ--2079选课时间(题目已修改,注意读题)

    选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 2079 选课时间

    hdu 2079 选课时间 题意:选的学分总和为n,并且学分为a的课有b种,总共有K(1<=k<=8)种学分不同的课,并且要选的学分最多为40:问选课方案有多少种?(学分相同的课即认为相同 ...

  6. hdu 2079 选课时间_母函数

    题意:需要学够n学分,有k个情况(x学分,y个相同学分的课) 解法:套母函数模板 #include <iostream> #include<cstdio> using name ...

  7. 2079 ACM 选课时间 背包 或 母函数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2079 题意:同样的学分 ,有多少种组合数,注意同样学分,课程没有区别 思路:两种方法 背包 母函数 背包: ...

  8. hdu2079 选课时间(题目已修改,注意读题) 母函数

    计算数的和的种类,母函数裸题 #include<stdio.h> #include<string.h> ],c2[],a,b; int main(){ int T; while ...

  9. HDU 2079 选课时间(母函数模板题)

    链接:传送门 思路:母函数模板题 /************************************************************************* > Fil ...

随机推荐

  1. angularJS批量删除 品优购删除品牌(通用复选框批量选中删除解决思路)

    思路: 一步:在点击复选框时维护变量数组 在js中定义一个数组变量, 给复选框添加点击动作, 在动作中判断当前复选框是否为选中状态(即点击后复选框的是否选中状态), 若为选中状态,则向数组中添加选中的 ...

  2. Ubuntu 14.04 64bit下Caffe + Cuda6.5/Cuda7.0 安装配置教程

    http://www.embeddedlinux.org.cn/emb-linux/entry-level/201612/21-6005.html 随着深度学习快速发展的浪潮,许多有兴趣的工作者都转入 ...

  3. 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 ...

  4. 2115: [Wc2011] Xor (线性基+dfs)

    2115: [Wc2011] Xor Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 5714  Solved: 2420 题目链接:https://w ...

  5. Intervals ZOJ - 3953 (区间贪心)

    Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that ...

  6. Bazinga 字符串HASH 这题不能裸HASH 要优化 毒瘤题

    Ladies and gentlemen, please sit up straight. Don't tilt your head. I'm serious. For nn given string ...

  7. 题解【luogu4168 [Violet]蒲公英】

    Description 给出一个长度为 \(n\) 序列 \(a\) ,\(m\) 次询问,每次询问区间 \([l,r]\) 里的众数(出现次数最多的数).若有多个,输出最小的. \(a_i \leq ...

  8. sublime text3常用快捷键

    Ctrl+L 选择整行(按住-继续选择下行) Ctrl+KK 从光标处删除至行尾 Ctrl+Shift+K 删除整行 Ctrl+Shift+D 复制光标所在整行,插入在该行之前 Ctrl+J 合并行( ...

  9. MySql 利用函数 查询所有子节点

    前提:mysql  函数  find_in_set(str,strlist), cast(value as type)   一.find_in_set(str,strlist):如果字符串str是在的 ...

  10. SPOJ AMR11E Distinct Primes 基础数论

    Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger i ...