解题报告:最多有8种学分的课,然后每种学分的课最多有10门,问要选学分为n的课一共有多少种选法,注意学分相同的课之间没有区别。

这题暴力可过,我用了8层循环,就简单了。听说可以用母函数,但没学过,看一下。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
int score[];
int main() {
int T,n,k,x,y;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&k);
memset(score,,sizeof(score));
while(k--) {
scanf("%d%d",&x,&y);
score[x] = y;
}
int tot = ;
for(int a = ;a<=score[]&&a<=n;++a)
for(int b = ;b<=score[]&&a+*b<=n;++b)
for(int c = ;c<=score[]&&a+*b+*c<=n;++c)
for(int d = ;d<=score[]&&a+*b+*c+*d<=n;++d)
for(int e = ;e<=score[]&&a+*b+*c+*d+*e<=n;++e)
for(int f = ;f<=score[]&&a+*b+*c+*d+*e+*f<=n;++f)
for(int g = ;g<=score[]&&a+*b+*c+*d+*e+*f+*g<=n;++g)
for(int h = ;h<=score[]&&a+*b+*c+*d+*e+*f+*g+*h<=n;++h)
if(a+*b+*c+*d+*e+*f+*g+*h == n)
tot++;
printf("%d\n",tot);
}
return ;
}

HDU 2079 选课时间 组合题的更多相关文章

  1. hdu 2079 选课时间

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

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

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

  3. hdu 2079 选课时间(题目已修改,注意读题)

    http://acm.hdu.edu.cn/showproblem.php?pid=2079 背包 #include <cstdio> #include <cstring> # ...

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

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

  5. hdu 2079 选课时间(题目已改动,注意读题) (母函数)

    代码: #include<cstdio> #include<cstring> using namespace std; int main() { int t; scanf(&q ...

  6. 杭电ACM hdu 2079 选课时间 (模板)

    Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合.你来帮帮他吧.(xhd认为一样学分的课没区别) Input输入 ...

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

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

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

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

  9. HDU 2078 选课时间( 水题 )

    链接:传送门 思路:水题略 /************************************************************************* > File N ...

随机推荐

  1. 关于对i++,++i的理解

    i++,代表 先赋值,在加:++i,代表先自加再赋值:后台console例子中可以看到第一个例子:var a= i++;  i是等于1的:先赋值,所以打印出a =1的:而i++后为2:所以打印出a = ...

  2. 2018最新Web前端经典面试试题及答案

    javascript: JavaScript中如何检测一个变量是一个String类型?请写出函数实现 typeof(obj) === "string" typeof obj === ...

  3. Word Ladder II Graph

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  4. Python日记——nginx+Gunicorn部署你的Flask项目

    转自:http://blog.csdn.net/qq_32198277/article/details/52432890 大家在学习Python的时候常常都是输入 python 文件名.py   这样 ...

  5. Qt——基本工具的使用

    本文主要介绍在windows系统中使用C++编写Qt程序所需要的一些工具,不会具体地讲工具怎么使用. 其它系统的安装本文不会涉及,在http://wiki.qt.io/Main中,有关于各种系统qt安 ...

  6. CF1083C Max Mex 线段树

    题面 CF1083C Max Mex 题解 首先我们考虑,如果一个数x是某条路径上的mex,那么这个数要满足什么条件? 1 ~ x - 1的数都必须出现过. x必须没出现过. 现在我们要最大化x,那么 ...

  7. 读取Maven项目下resources目录下的配置文件(properties为例)

    配置文件:xxxxx.properties a.url=******************** b.url=---------------------------------- 读取配置文件: im ...

  8. beego 返回 json 响应

    需要注意的是 json 结构体里面的字段必须是大写字母开头,否则是不会返回的. 我们可以起个别名: type person struct { Name string `json:"name& ...

  9. mac go2shell 安裝

    配合Finder打开Finder,按住command键,拖动Go2Shell的图标到Finder菜单就可以在Finder快捷打开Go2Shell了

  10. UML类图与类间六种关系表示

    UML类图与类间六种关系表示 1.类与类图 类封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性,操作,关系的对象集合的总称. 类图是使用频率最高的UML图之一. 类图用于描述系统中所包含的 ...