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 ...
随机推荐
- Hibernate_day02
一.今天内容 1 实体类编写规则 2 hibernate主键生成策略 (1)native (2)uuid 3 实体类操作 (1)crud操作 (2)实体类对象状态 4 hibernate的一级缓存 5 ...
- QDoubleSpinBox浮点型数字调节框
样式: import sys from PyQt5.QtWidgets import QApplication, QWidget, QDoubleSpinBox class Demo(QWidget) ...
- mysql数据库备份和恢复
1.数据库备份 mysqldump -uroot -proot jira736 > jira736.sql 2.数据库恢复 mysql -uroot -proot jira762 < ji ...
- Navicat Premium连接各种数据库
版本信息 Navicat Premium 是一套数据库开发工具,让你从单一应用程序中同时连接 MySQL.MariaDB.SQL Server.Oracle.PostgreSQL 和 SQLite 数 ...
- Python(十三)python的函数重载
首先,重载函数的功能是实现参数不同情况下功能相同的函数. 函数重载的目的是解决功能相同的函数的以下问题: 1.参数的类型: 2.参数的个数: 对于情况1,函数功能呢相同,参数不同的情况. python ...
- java读取视频文件时长
1.下载jar包:http://www.sauronsoftware.it/projects/jave/index.php 2.上代码 @RequestMapping(value = "am ...
- 在使用kvc进行赋值的时候,有时候会遇到null值,这个时候我们使用kvc会报错
在使用kvc进行赋值的时候,有时候会遇到null值,这个时候我们使用kvc会报错,如何解决 控制器代码如下: // // ViewController.m // 02-模型中的赋值 // // Cre ...
- CSS如何进行图文并茂布局怎么破
上下结构 左右结构 右边左边的结构
- ubuntu 下 teamview 取消自动启动 autostart
sudo teamviewer daemon disable
- python根据服务名获取服务启动路径
#coding=utf8 import _winreg as winreg class Win32Environment: """Utility class to get ...