题目: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】选课时间(母函数)的更多相关文章

  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. JavaScript关键字return的用法

    return 语句从当前函数退出,并从那个函数返回一个值. 语法: 1 return[()[expression][]]; 可选项 expression 参数是要从函数返回的值.如果省略,则该函数不返 ...

  2. best code #54 div 2 A 水

    A problem of sorting Accepts: 443 Submissions: 1696 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  3. kali wireless driver install

    acer-gateway nv47h94c 1.lspci -nn |grep 0280 get pci-id root@silee:/# lspci -nn |grep 028003:00.0 Ne ...

  4. java 课后作业

    杨辉三角 组合数 public class YH { public static void main(String agrs[]) { int a[5][5],i,j; for(i = 0;i < ...

  5. JS如何判断是不是iphoneX

    function isIphoneX(){ return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 & ...

  6. [LeetCode] 19. Remove Nth Node From End of List ☆

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  7. [Luogu 3966] TJOI 2013 单词

    经典ACAM. 注意单词之间添加字符,以及对重复单词的处理. #include <cstdio> #include <cstring> #include <queue&g ...

  8. 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法

    使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,会报异常. 例如: <select id="getPersonRecordId" parameterTy ...

  9. java 7修改文件权限

    Full control over file attributes is available in Java 7, as part of the "new" New IO faci ...

  10. CentOS 7 vim显示中文乱码

    使用xshell的时候,发现有时候中文显示有乱码,一开始以为是Xshell没设置好,后来检查了一下xshell<<文件<<属性<<终端:右侧编码,显示的是Unico ...