题目不太好读懂,就是先给你一个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. PostgreSQL 备忘

    truncate table page_frame_mst; select setval('page_frame_mst_id_seq', 1, false): select setval('imag ...

  2. Java Servlet JSP编程(一)

    最近想学学java编程,java现在的应用还是挺广泛的,有必要学习一下. # index.jsp <%@ page language="java" contentType=& ...

  3. Flask框架 之request对象

    一.request对象属性 属性 说明 类型 data 记录请求的数据,并转换为字符串 * form 记录请求中的表单数据 MultiDict args 记录请求中的查询参数 MultiDict co ...

  4. mac install telnet

    问题: -bash: telnet: command not found -bash: brew: command not found 解决: /usr/bin/ruby -e "$(cur ...

  5. Oracle XE WM_CONCAT undifine

    用docker 跑了个oracle XE 报错 没有WM_CONCAT    下载三个sql文件然后按顺序执行后可以正常使用 一:下载三个文件 解压到 oracle 目录下面 (要能找到,注意权限要o ...

  6. Mybatis中and和or的细节处理

    当一条SQL中既有条件查又有模糊查的时候,偶尔会遇到这样的and拼接问题.参考如下代码: <select id="listSelectAllBusiness"> sel ...

  7. MySQL-date和datetime

    MySQL中 date表示只有日期: insert into stu values(id = null, birthday = '2000-01-11'); datetime则还包含了时间: inse ...

  8. 【01】bootstrap基本信息

    [01]基本信息   中文官网:http://www.bootcss.com/ 英文官网:https://github.com/twbs/bootstrap/   支持IE8+   CND : htt ...

  9. noip模拟赛 天天和不可描述

    分析:直接就这么翻肯定是不行的,换一种想法:有括号就是把括号里的字符串倒着输出,如果在括号里又遇到了括号就继续倒着输出,相当于递归. 我们可以用递归直接做,也可以用一层循环搞定,每次从左括号跳到右括号 ...

  10. T5090 众数 codevs

    http://codevs.cn/problem/5090/ 时间限制: 1 s  空间限制: 1000 KB  题目等级 : 青铜 Bronze 题目描述 Description 由文件给出N个1到 ...