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的更多相关文章

  1. Codeforces 788C The Great Mixing(背包问题建模+bitset优化或BFS)

    [题目链接] http://codeforces.com/problemset/problem/788/C [题目大意] 给出一些浓度的饮料,要求调出n/1000浓度的饮料,问最少需要多少升饮料 [题 ...

  2. Codeforces.788C.The Great Mixing(bitset DP / BFS)

    题目链接 \(Description\) 有k种饮料,浓度Ai给出,求用最少的体积配成n/1000浓度的饮料. \(Solution\) 根据题意有方程 (A1x1+A2x2+...+Anxn)/[( ...

  3. 【Codeforces 788C】The Great Mixing

    http://codeforces.com/contest/788/problem/C 显然如果有两杯一样的酒,把它们当作同一杯就好了.所以k<=1e6毫无意义. 若选的x杯酒的浓度分别为a,b ...

  4. 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 ...

  5. Codeforces 788 C. The Great Mixing

    题目链接:http://codeforces.com/contest/788/problem/C 一看就不能暴力$DP$,我们可以将浓度的合并操看作为在追逐一高度,每次操作前这个高度都会向上走$n$, ...

  6. Educational Codeforces Round 88 (Rated for Div. 2) C. Mixing Water(数学/二分)

    题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二 ...

  7. Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water

    题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...

  8. CodeForces 445B DZY Loves Chemistry

    DZY Loves Chemistry Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  9. CodeForces 445B. DZY Loves Chemistry(并查集)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://codeforces.com/problemset/prob ...

随机推荐

  1. 表格控件QTableWidget

    搭配QTableWidgetItem使用 样式: import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplica ...

  2. 字体QFont

    import sys from PyQt5.QtWidgets import QApplication, QWidget,QLabel from PyQt5.QtGui import QFont fr ...

  3. 发现一sonar-runner bug

    最近在使用sonar-runner做代码扫描, 在windows环境运行多模块的扫描ok,但是在linux上sonar-runner扫描多模块报错: 先贴sonar-project.propertie ...

  4. Oracle设置某张表为只读

    Oracle 11g开始支持设置某张表为只读,这样可以防范对某些表的修改,起到一定的安全性. 设置如下: --设置表为只读权限(加锁) ALTER TABLE tab_name READ ONLY ; ...

  5. postman变量的使用和设置

    之前只是使用postman做接口管理——将各个项目使用到的接口分类管理起来,用的时候手动改参数调用.这次项目连着跑三个接口,需要用到前一个接口的参数,还来回切平台,真的很麻烦,所以就搜了一下有什么便利 ...

  6. Biorhythms HDU - 1370 (中国剩余定理)

    孙子定理: 当前存在三个式子,t%3=2,t%5=3,t%7=2.然后让你求出t的值的一个通解. 具体过程:选取3和5的一个公倍数t1能够使得这个公倍数t1%7==1,然后选取3和7的一个公倍数t2使 ...

  7. C - Least Crucial Node

    题目链接:https://cn.vjudge.net/contest/247936#problem/C 具体大意:给你起点和中点,总点数,边数.求到终点的最小割点. 具体思路:可以用tarjan算法来 ...

  8. Docker容器数据卷

    ⒈Docker容器中数据如何持久化? ①通过commit命令使容器反向为镜像 ②以容器数据卷的方式将数据抽离 ⒉容器数据卷的作用? ①容器数据的持久化 ②容器间继承.共享数据 ⒊能干嘛? 卷就是目录或 ...

  9. 说说流控制(RTS/CTS/DTR/DSR 你都明白了吗?)【转】

    转自:http://bbs.ednchina.com/BLOG_ARTICLE_129041.HTM 以前写的博文,转过来 ============== 先引用一篇网文,作者不详,因几个地方都说自己是 ...

  10. java linux ftp问题

    java写的ftp上传类,本地测试环境可以用,阿里云服务器不可用,两者系统均为centos.经过测试,发现appche的ftpclient类不可用,换成sun的ftpclient可以使用.