Codeforces 788C The Great Mixing
化简一下公式后发现, 问题变成了, 取最少多少数能使其和为1, bitset优化一下背包就好啦。
题解中介绍了一种bfs的方法没, 感觉比较巧妙。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, k, a[N];
bitset<> dp[N]; int main() {
scanf("%d%d", &n, &k);
for(int i = ; i <= k; i++) scanf("%d", &a[i]);
for(int i = ; i <= k; i++) {
if(a[i] == n) {
puts("");
return ;
}
a[i] -= n;
}
sort(a + , a + + k);
k = unique(a + , a + + k) - a - ;
dp[][] = ;
for(int i = ; i <= ; i++) {
for(int j = ; j <= k; j++) {
if(a[j] >= ) dp[i] |= dp[i - ] << a[j];
else dp[i] |= dp[i - ] >> (-a[j]);
if(dp[i][]) {
printf("%d\n", i);
return ;
}
}
}
puts("-1");
return ;
} /*
*/
Codeforces 788C The Great Mixing的更多相关文章
- Codeforces 788C The Great Mixing(背包问题建模+bitset优化或BFS)
[题目链接] http://codeforces.com/problemset/problem/788/C [题目大意] 给出一些浓度的饮料,要求调出n/1000浓度的饮料,问最少需要多少升饮料 [题 ...
- Codeforces.788C.The Great Mixing(bitset DP / BFS)
题目链接 \(Description\) 有k种饮料,浓度Ai给出,求用最少的体积配成n/1000浓度的饮料. \(Solution\) 根据题意有方程 (A1x1+A2x2+...+Anxn)/[( ...
- 【Codeforces 788C】The Great Mixing
http://codeforces.com/contest/788/problem/C 显然如果有两杯一样的酒,把它们当作同一杯就好了.所以k<=1e6毫无意义. 若选的x杯酒的浓度分别为a,b ...
- Codeforces 789e The Great Mixing (bitset dp 数学)
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th typ ...
- Codeforces 788 C. The Great Mixing
题目链接:http://codeforces.com/contest/788/problem/C 一看就不能暴力$DP$,我们可以将浓度的合并操看作为在追逐一高度,每次操作前这个高度都会向上走$n$, ...
- Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)
题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...
- Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water
题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...
- CodeForces 445B DZY Loves Chemistry
DZY Loves Chemistry Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- CodeForces 445B. DZY Loves Chemistry(并查集)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://codeforces.com/problemset/prob ...
随机推荐
- UEditor百度编辑器,工具栏自定义添加一个普通按钮
根据网上前辈提供的,还真的不错,下面也整理一下 添加一个名叫“macros”的普通按钮在工具栏上: 第一步:找到ueditor.config.js文件中的toolbars数组,增加一个“macros” ...
- luogu 1993 小K的农场
差分约束+spfa判负环 dfs判负环 #include<bits/stdc++.h> #define rep(i,x,y) for(register int i=x;i<=y;i+ ...
- Zabbix 监控服务
熟悉了解一些 zabbix 基础项目监控 zabbix_get 相关操作 :获取 item 监控数据 基本格式: -s --host: 指定客户端主机名或者IP -p --port:客户端端口,默认 ...
- Go 语言读书笔记
Go语言的设计理念很明确,就是将动态类型语言的编程容易度和静态类型语言的安全效率结合起来. Go语言,又称Golang,是Google开发的一款静态强类型.编译型.并发型,并具有垃圾回收机制的 ...
- 转载 int和string 类型的互换
https://blog.csdn.net/u012421436/article/details/51386690 不论是在什么语言下编程(除C,因为C是没有string类型的),int与string ...
- HashMap、ArrayMap、SparseArray分析比较
http://blog.csdn.net/chen_lifeng/article/details/52057427
- 【windows核心编程】系统消息与自定义钩子(Hook)使用
一.HOOk Hook是程序设计中最为灵活多变的技巧之一,在windows下,Hook有两种含义: 1.系统提供的消息Hook机制 2.自定义的Hook编程技巧 其中,由系统提供的消息钩子机制是由一系 ...
- TypeError: 'range' object does not support item assignment
TypeError: 'range' object does not support item assignment I was looking at some python 2.x code and ...
- springboot系列一、springboot产生背景及介绍
一.为什么用Springboot 长期以来 Java 的开发一直让人所诟病: ·Java 项目开发复杂度极其高: · Java 项目的维护非常困难: · 在云时代如何实现项目的快速部署以及快速启动: ...
- 如何在windows上调试安卓机谷歌浏览器上的页面
- 下面的方法仅在windows和安卓机上测试过,,,, - 手机(安卓机)需要安装chrome与电脑(Windows)上的chrome配合,也就是只能调试谷歌浏览器上的页面 1.手机的准备工作 打开 ...