URAL 1326. Bottle Taps(简单的状压dp)
题目不太好读懂,就是先给你一个n代表要从n个物品中买东西,然后告诉你这n个东西的单位价格,在给你m个集合的情况。就是每一个结合中有x件物品。他们合起来买的价格是k。这x件物品依次是:p1……px。之后给你一个kk,表示你要买的物品的编号。
让你求出来怎样花费最少的钱买到要求的序列。
20。能够状压啊。注意一開始的时候先把单位价格的状态处理出来。。。之后就是水题了啊。
1326. Bottle Taps
Memory limit: 64 MB
sell him these taps. Some of the programmers sell the taps in sets with big discounts.
cheap as possible.
Input
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
Sample
| input | output |
|---|---|
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)的更多相关文章
- 【BZOJ3814】【清华集训2014】简单回路 状压DP
题目描述 给你一个\(n\times m\)的网格图和\(k\)个障碍,有\(q\)个询问,每次问你有多少个不同的不经过任何一个障碍点且经过\((x,y)\)与\((x+1,y)\)之间的简单回路 \ ...
- POJ 3311 Hie with the Pie (状压DP)
dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推 ...
- 状压dp Codeforces Beta Round #8 C
http://codeforces.com/contest/8/problem/C 题目大意:给你一个坐标系,给你一个人的目前的坐标(该坐标也是垃圾桶的坐标),再给你n个垃圾的坐标,这个人要捡完所有的 ...
- HDU 5067 Harry And Dig Machine(状压DP)(TSP问题)
题目地址:pid=5067">HDU 5067 经典的TSP旅行商问题模型. 状压DP. 先分别预处理出来每两个石子堆的距离.然后将题目转化成10个城市每一个城市至少经过一次的最短时间 ...
- hdu 2809(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...
- BZOJ5299:[CQOI2018]解锁屏幕(状压DP)
Description 使用过Android手机的同学一定对手势解锁屏幕不陌生.Android的解锁屏幕由3x3个点组成,手指在屏幕上画一条 线将其中一些点连接起来,即可构成一个解锁图案.如下面三个例 ...
- 对状压dp的见解
看了好几篇博客,终于对一些简单的状压dp有了点了解.就像HDU1074. 有个博客:https://blog.csdn.net/bentutut/article/details/70147989 感觉 ...
- 状压dp之二之三 炮兵阵地/玉米田 By cellur925
一.简单的状压dp 玉米田 题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ ...
- B1072 [SCOI2007]排列perm 状压dp
很简单的状压dp,但是有一个事,就是...我数组开大了一点,然后每次memset就会T,然后开小就好了!!!震惊!以后小心点这个问题. 题干: Description 给一个数字串s和正整数d, 统计 ...
随机推荐
- java多线程之内存的可见性介绍(备用1)
(仅供参考) a.共享变量的可见能够一定程度保证线程安全,共享变量不可见导致数据不够准确,出现各种各样的问题,导致线程不安全. b.不同线程之间无法直接访问其他线程工作内存中的变量. 1.可见性 2. ...
- [转]汇编语言:MOVSB,MOVSW,MOVSD
汇编语言:MOVSB,MOVSW,MOVSD 转自: http://blog.csdn.net/zhenyongyuan123/article/details/8364011 目前80386系列的 ...
- CentOS下安装微软雅黑字体
CentOS下安装微软雅黑字体 微软雅黑下载地址:http://download.csdn.net/detail/u012547633/9796219 1.先从你本机 C:\Windows\Fon ...
- HTML5大数据可视化效果(一)彩虹爆炸图
前言 25年过去了,Brooks博士著名的“没有银弹”的论断依旧没有被打破.HTML5也是一样.但这并不妨碍HTML5是一个越来越有威力的“炸蛋”:发展迅速.势不可挡.随着HTML5技术的普及,用HT ...
- php第二十四节课
三级联动 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- no bundle URL present in react-native?
Assuming that you are using nvm and multiple versions of node installed, here is the solution: Say t ...
- css--小白入门篇4
一.前文回顾 盒模型box model 什么是盒子?所有的标签都是盒子.无论是div.span.a都是盒子.图片.表单元素一律看做文本. 盒模型有哪些组成:width.height.padding.b ...
- poj3061 Subsequence【尺取法】
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- Java第九周总结
- 爬楼梯,N级楼梯有多少种走法?
https://blog.csdn.net/tcpipstack/article/details/45173685 一个人爬楼梯,一步可以迈一级,二级,三级台阶,如果楼梯有N级,要求编写程序,求总共有 ...