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. Hibernate or 的用法

    转自baidu estrictions.or(Restrictions.like(),Restrictions.or(Restrictions.like,........))里面的or可以无限加的.还 ...

  2. Dojo框架:误解与现实[转载]

    随着Ajax技术的流行,越来越多的Web应用使用Ajax技术来提高用户体验.使用Ajax技术的一个重要优势是不需要额外的浏览器插件支持,只需要使用浏览器原生的API,并利用JavaScript来操作即 ...

  3. Java读取Txt封装到对象中——(三)

    JavaBean package bean; public class Question { private String timu; //题干 private String leixing; //类 ...

  4. SVM实例及Matlab代码

    ******************************************************** ***数据集下载地址 :http://pan.baidu.com/s/1geb8CQf ...

  5. Centos7.5 防火墙设置

    Centos7.5默认使用firewalld作为防火墙 1.查看firewalld服务状态 systemctl status firewalld 2.查看firewalld的状态 firewall-c ...

  6. Pytorch 之 backward

    首先看这个自动求导的参数: grad_variables:形状与variable一致,对于y.backward(),grad_variables相当于链式法则dz/dx=dz/dy × dy/dx 中 ...

  7. 为caffe添加最简单的全通层AllPassLayer

    参考赵永科的博客,这里我们实现一个新 Layer,名称为 AllPassLayer,顾名思义就是全通 Layer,“全通”借鉴于信号处理中的全通滤波器,将信号无失真地从输入转到输出. 虽然这个 Lay ...

  8. UML和模式应用3:迭代和进化式分析和设计案例研究

    1.前言 如何进行迭代和进化式分析和设计?将采用案例研究的方式贯穿始终.案例研究所包含的内容: UI元素 核心应用逻辑层 数据库访问 与外部软硬构件的协作 本章关于OOA/D主要介绍核心应用逻辑层 2 ...

  9. c# WinFo判断当前程序是否已经启动或存在的几种方式

    第一种方式:利用Mutex互斥量实现同时只有一个进程实例在运行 static class Program { /// <summary> /// 应用程序的主入口点. /// </s ...

  10. C++:__stdcall详解

    原文地址:http://www.cnblogs.com/songfeixiang/p/3733661.html 对_stdcall 的理解(上)在C语言中,假设我们有这样的一个函数:int funct ...