题目不太好读懂,就是先给你一个n代表要从n个物品中买东西,然后告诉你这n个东西的单位价格,在给你m个集合的情况。就是每一个结合中有x件物品。他们合起来买的价格是k。这x件物品依次是:p1……px。之后给你一个kk,表示你要买的物品的编号。

让你求出来怎样花费最少的钱买到要求的序列。

20。能够状压啊。注意一開始的时候先把单位价格的状态处理出来。。。之后就是水题了啊。

1326. Bottle Taps

Time limit: 3.0 second

Memory limit: 64 MB
Programmer Petrov has a hobby to collect beer-bottle taps. There’s nothing unusual — he knows hundreds of programmers that like beer. And they collect taps, too. Not everyone, but some of them.
Frankly speaking, he has bought a part of his collection. But unfortunately he hasn’t got some rare taps to complete his collection. He has found some programmers over the Internet that are ready to
sell him these taps. Some of the programmers sell the taps in sets with big discounts.
It’s left to find an optimal offer. Petrov can explain to his wife why he is to store the taps but he won’t be able to prove why he is to spend money for the collection. So he is to buy the taps as
cheap as possible.
Petrov has written down all the variants and has started thinking. There’s no way to find out the solution of the problem without a program!

Input

The first line contains an integer N, an amount of available taps (1 ≤ N ≤ 20). The following Nlines contain prices of bottles with the taps if one buys them
in stores. The next line contains an integer M (0 ≤ M ≤ 100) — an amount of offers to sell the taps. The following M lines describe the sets. The first number of each line is the price of the set and the second one is
the amount of taps in the set. Then there are numbers of the taps in the set (each number lies in the range from 1 to N). The numbers in a set are unique. All the prices are positive integers and do not exceed 1000. The last line begins with the amount
of taps that Petrov plans to buy. Then their numbers follow separated by spaces. These numbers are unique, too.

Output

Output the minimal sum of money that Petrov should spend on obtaining the necessary taps.

Sample

input output
4
10
11
12
13
3
17 2 1 3
25 3 2 3 4
15 2 3 4
3 1 3 4
25

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL __int64
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898 const int maxn = 1010; using namespace std; int dp[1<<22];
int num[maxn];
int f[maxn];
int st[maxn];
int n; void dfs(int x, int y, int z)
{
if(x == n)
{
dp[y] = z;
return;
}
dfs(x+1, y, z);
dfs(x+1, y|(1<<x), z+num[x]);
} int main()
{
while(~scanf("%d",&n))
{
for(int i = 0; i < (1<<n); i++) dp[i] = INF;
for(int i = 0; i < n; i++) scanf("%d",&num[i]);
dfs(0, 0, 0);
int m;
scanf("%d",&m);
for(int i = 0; i < m; i++)
{
scanf("%d",&f[i]);
int x;
scanf("%d",&x);
int sum = 0;
int tmx;
for(int j = 0; j < x; j++)
{
scanf("%d",&tmx);
sum |= (1<<(tmx-1));
}
st[i] = sum;
}
int kk;
scanf("%d",&kk);
int ans = 0;
int p;
for(int i = 0; i < kk; i++)
{
scanf("%d", &p);
ans |= (1<<(p-1));
}
int Min = INF;
for(int i = 0; i < (1<<n); i++)
{
if((i&ans) == ans) Min = min(Min, dp[i]);
for(int j = 0; j < m; j++) dp[i|st[j]] = min(dp[i|st[j]], dp[i]+f[j]);
}
printf("%d\n",Min);
}
return 0;
}

URAL 1326. Bottle Taps(简单的状压dp)的更多相关文章

  1. 【BZOJ3814】【清华集训2014】简单回路 状压DP

    题目描述 给你一个\(n\times m\)的网格图和\(k\)个障碍,有\(q\)个询问,每次问你有多少个不同的不经过任何一个障碍点且经过\((x,y)\)与\((x+1,y)\)之间的简单回路 \ ...

  2. POJ 3311 Hie with the Pie (状压DP)

    dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推 ...

  3. 状压dp Codeforces Beta Round #8 C

    http://codeforces.com/contest/8/problem/C 题目大意:给你一个坐标系,给你一个人的目前的坐标(该坐标也是垃圾桶的坐标),再给你n个垃圾的坐标,这个人要捡完所有的 ...

  4. HDU 5067 Harry And Dig Machine(状压DP)(TSP问题)

    题目地址:pid=5067">HDU 5067 经典的TSP旅行商问题模型. 状压DP. 先分别预处理出来每两个石子堆的距离.然后将题目转化成10个城市每一个城市至少经过一次的最短时间 ...

  5. hdu 2809(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...

  6. BZOJ5299:[CQOI2018]解锁屏幕(状压DP)

    Description 使用过Android手机的同学一定对手势解锁屏幕不陌生.Android的解锁屏幕由3x3个点组成,手指在屏幕上画一条 线将其中一些点连接起来,即可构成一个解锁图案.如下面三个例 ...

  7. 对状压dp的见解

    看了好几篇博客,终于对一些简单的状压dp有了点了解.就像HDU1074. 有个博客:https://blog.csdn.net/bentutut/article/details/70147989 感觉 ...

  8. 状压dp之二之三 炮兵阵地/玉米田 By cellur925

    一.简单的状压dp 玉米田 题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ ...

  9. B1072 [SCOI2007]排列perm 状压dp

    很简单的状压dp,但是有一个事,就是...我数组开大了一点,然后每次memset就会T,然后开小就好了!!!震惊!以后小心点这个问题. 题干: Description 给一个数字串s和正整数d, 统计 ...

随机推荐

  1. 小知识~清除系统盘的Hiberfil.sys

    Hiberfil.sys这个文件是系统休眠用的,时间长了你可能会占用几个G的磁盘空间,有时我们并不需要它,而又无法直接删除,这时,你可以使用CMD命令来关闭这个功能,关闭后,这个文件自动被删除. 1 ...

  2. ASP.NET跨页面传值技巧[总结]

    个人网站:http://www.51pansou.com .net视频下载:.net视频教程 .net源码下载:.net源码 关于页面传值的方法,我就我个人观点做了些总结,希望对大家有所帮助. 1.  ...

  3. 【sqli-labs】 对于less34 less36的宽字节注入的一点深入

    1.AddSlashes() 首先来观察一下是如何通过构造吃掉转义字符的 先将less 34的网页编码换成gbk 加上一些输出 echo "Before addslashes(): &quo ...

  4. Masonry 原理与使用说明

    原理: 1)约束生成:MASConstraintMaker: 2)缺省补齐: - (void)setSecondViewAttribute:(id)secondViewAttribute { if ( ...

  5. day21-1 类的继承

    目录 类的继承 什么是继承 为什么用继承 对象的继承 继承与抽象 继承的应用 对象属性查找顺序 类的继承 什么是继承 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承) ...

  6. 初步认识MVC

     一丶路由(One) 自定义路由,静态路由,动态路由,组合路由 routes.MapRoute 二丶Action向View传值的四种方式(ViewData.ViewBag.TempData.Model ...

  7. spark学习(3)---集合

    一.list https://blog.csdn.net/xianpanjia4616/article/details/84930779 华为文档:https://support.huawei.com ...

  8. thymeleaf的使用及配置

    * th:action    <form id="login" th:action="@{/login}">......</form>  ...

  9. php第二十三节课

    XML XML:页面之间传递数据,跨平台传递 HTML:超文本标记语言,核心标签 XML特点:1.标签名可以自己定义2.有且只有一个根3.大小写敏感4.标签必须完整 <!DOCTYPE html ...

  10. printf函数压栈(i++/i--,++i/--i) 终极解密

    #include <stdio.h> void main() { ; printf("%d %d %d %d\n", i, --i, i, i--); } 输出是“3 ...