2019牛客假日团队赛3 - 牛奶披萨(dfs,HashSet)

链接:https://ac.nowcoder.com/acm/contest/945/A
来源:牛客网

Description

有T种馅料,但有些馅料不能被放在一起。求选出一些馅料的方案数是多少。
文件输入第一行为两个整数 T 和 N(T≤20,N≤52),N表示接下来N行会有N个限制。
接下来N行,每行的第一个数Z表示接下来数的个数:a1,a2…az,表示任意一种陷料中这z种馅料不能同时出现。
如果Z=1,则表示a1 这种陷料在任何一种组合中都不得出现。
如果Z=3 a1=3 a2=4 a3=6 表示3,4,6 三种馅料不能在任何一种组合中出现。

Input

Line 1: Two space-separated integers: T and N
Lines 2…N+1: Each line describes a constraint using space-separated
The first integer is the number of ingredients in constraint, Z (1 <= Z <= T). The subsequent Z integers (which are unique) list the ingredient(s) whose combination a pizza from consideration for the cows.

Output

Line 1: A single integer that is the total number of pizzas that can be created using the number of ingredients and constraints.

Input sample

6 5
1 1
2 4 2
3 3 2 6
1 5
3 3 4 6

Output sample

10

直接dfs,由于限制较少,可以对某一种限制直接遍历一遍检查是否冲突即可

/*
 * Copyright (c) 2019 Ng Kimbing, HNU, All rights reserved. May not be used, modified, or copied without permission.
 * @Author: Ng Kimbing, HNU.
 * @LastModified:2019-06-25 T 10:24:39.181 +08:00
 */

package ACMProblems.QianDaoTi;

import java.util.HashSet;
import java.util.Set;

import static ACMProblems.ACMIO.*;

/*
 * 链接:https://ac.nowcoder.com/acm/contest/945/A
 * 来源:牛客网
 *
 * ## Description
 *
 * 有T种馅料,但有些馅料不能被放在一起。求选出一些馅料的方案数是多少。
 * 文件输入第一行为两个整数 T 和 N(T≤20,N≤52),N表示接下来N行会有N个限制。
 * 接下来N行,每行的第一个数Z表示接下来数的个数:a1,a2......az,表示任意一种陷料中这z种馅料不能同时出现。
 * 如果Z=1,则表示a1 这种陷料在任何一种组合中都不得出现。
 * 如果Z=3 a1=3 a2=4 a3=6 表示3,4,6 三种馅料不能在任何一种组合中出现。
 *
 * ## Input
 *
 * Line 1: Two space-separated integers: T and N
 * Lines 2..N+1: Each line describes a constraint using space-separated
 * The first integer is the number of ingredients in constraint, Z (1 <= 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值