题目链接:http://codeforces.com/contest/788/problem/C


  一看就不能暴力$DP$,我们可以将浓度的合并操看作为在追逐一高度,每次操作前这个高度都会向上走$n$,每次加入一定浓度的汽水就增加了相应的高度$a_i$,由于每次都是进行相同的转移,所以一旦高度差的绝对值大于了$1000$,这个状态就没有了意义(因为一定会有等价的状态比他更好),剪枝一下。所以每一次转移就是${O(n*min(k,1000))}$的。

  

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<map>
using namespace std;
#define maxn 10010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,k,a[maxn];
bool xian[maxn];
map<llg,bool>ma;
vector<llg>f,nf;
inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} int main()
{
// yyj("C");
cin>>n>>k;
for (llg i=;i<=k;i++)
{
llg x=getint();
if (xian[x]) continue;
xian[x]=;
a[++m]=x;
}
f.push_back();
for (llg tim=;;tim++)
{
if ((double)clock()/CLOCKS_PER_SEC>0.91) break;
ma.clear();
llg w=f.size(); nf.clear();
for (llg i=;i<w;i++)
{
llg val=f[i];
val-=n;
for (llg j=;j<=m;j++)
{
llg nval=val+a[j];
if (nval==)
{
cout<<tim;
return ;
}
if (nval> || nval<-) continue;
if (ma[nval]) continue;
ma[nval]=;
nf.push_back(nval);
}
}
f.clear();
w=nf.size();
for (llg i=;i<w;i++) f.push_back(nf[i]);
}
cout<<-;
return ;
}

Codeforces 788 C. The Great Mixing的更多相关文章

  1. 【Codeforces 788C】The Great Mixing

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

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

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

  3. Codeforces 788C The Great Mixing

    The Great Mixing 化简一下公式后发现, 问题变成了, 取最少多少数能使其和为1, bitset优化一下背包就好啦. 题解中介绍了一种bfs的方法没, 感觉比较巧妙. #include& ...

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

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

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

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

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

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

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

  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. 剑指offer——python【第43题】左旋转字符串

    题目描述 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S=”abc ...

  2. layer loading层 的设置

    /* shadeClose 类型:Boolean 默认:true,是否点击遮罩时关闭层 */ var tishi = layer.open({ shadeClose: false ,type: 2 , ...

  3. php计算几分钟前、几小时前、几天前的几个函数

    函数方法: /*php计算几分钟前.几小时前.几天前的几个函数*/ function get_date($time){ $t=time()-$time; $f=array( '31536000'=&g ...

  4. Linux基础:用tcpdump抓包(转)

    https://segmentfault.com/a/1190000012593192 https://segmentfault.com/a/1190000009691705

  5. 删除已渲染select标签的值

    var removeSaleTypeEnumIs2 = function(){ var sel = document.getElementById('saleType'); sel.remove(se ...

  6. Kruskal和prime算法的类实现,图的遍历BFS算法。

    一.图的遍历 #include<iostream> #include<queue> #include<vector> using namespace std; in ...

  7. finance1:专业词汇

    1,沙盘演练:沙盘演练又叫沙盘模拟培训.沙盘推演,源自西方军事上的战争沙盘模拟推演,是通过引领学员进入一个模拟的竞争性行业,由学员分组建立若干模拟公司,围绕形象直观的沙盘教具,实战演练模拟企业的经营管 ...

  8. jquery批量提交表单值 和批量设置表单值

    $('#frmCustomerConfirmCar').find('[name]').each(function () { var type = $(this)[0].nodeName.toLower ...

  9. makefile编写规则

    cc = g++ -std=c++11 prom = calc deps = FtTest.h obj = FtTest.o newft.o LIBS = -lgtest_c11 $(prom): $ ...

  10. java框架之SpringBoot(13)-检索及整合Elasticsearch

    ElasticSearch介绍 简介 我们的应用经常需要使用检索功能,开源的 Elasticsearch 是目前全文搜索引擎的首选.它可以快速的存储.搜索和分析海量数据.SpringBoot 通过整合 ...