题目不太好读懂,就是先给你一个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. linux nohup & 简单使用

    线上通常nohup配合&启动程序,同时免疫SIGINT和SIGHUP信号,从而保证程序在后台稳定运行 & 1.后台运行,输出默认到屏幕 2.免疫SIGINT信号,比如Ctrl+c不会杀 ...

  2. swift extension 的最终目的是结合

    与数据结合:对数据进行操作: 与行为结合:使用原有行为生成更便捷的行为: 与协议结合:实现协议: 与类型结合:对类型数据进行操作,添加新的行为: 与关联类型.泛型结合:对类型做出限定.

  3. margin与padding如何进行区分

    margin与padding如何进行区分,这是很多学html人的困扰,其实说白了padding 就是内容与边框的空隙.而margin则是模块与模块的空隙.[3]

  4. 08Oracle Database 完整性约束

    Oracle Database 完整性约束 非空约束 创建表时 Create table table_name( Column_name datatype NOT NULL,… ); 修改表时 Alt ...

  5. Vue组件传值方法调用

    1.子组件改变父组件的值 <father  label="云盘快照" name="name2"> <son :props='rows'   @ ...

  6. python的webservice请求

    1.pip install client 2.pip install suds-jurko #coding=utf-8from suds.client import Clientimport time ...

  7. Python基础之字符的编码

    参考原文 Python廖雪峰 为什么要进行编码? 计算机只能处理二进制数字(0100111),要处理文本,就必须先把文本转为数字才能处理,这个过程就叫编码. 字符的编码 ASCII编码 由于计算机是美 ...

  8. Android中ProgressDialog自动消失

    主要函数部分代码: final ProgressDialog proDialog = android.app.ProgressDialog .show(MainActivity.this, " ...

  9. cc.Node—事件响应

    触摸事件1: 触摸事件类型: START, MOVED, ENDED(物体内), CANCEL(物体外);2: 监听触摸事件: node.on(类型, callback, target(回掉函数的th ...

  10. Luogu P2847 [USACO20DEC]Moocast(gold)奶牛广播-金

    解题思路 要保证图是强连通的,用因为给出的边全部都是双向边.考虑树形的结构,在一棵树上的$N$个节点一定是强连通的.他们都能够互相到达.又要保证树上的$n-1$条边中的最长的一条边最小.那就用Krus ...