Codeforces 1079 E - The Unbearable Lightness of Weights
E - The Unbearable Lightness of Weights
思路:
分组背包dp
每组最多只能选一个
一些优化可以快很多
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = , M = 1e4 + ;
int cnt[N];
int dp[N][M];
int main() {
int n, a;
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%d", &a), cnt[a]++; dp[][] = ;
int dif = , tot = , sum = ;
for (int i = ; i < N; i++) {
if(cnt[i]) {
tot += cnt[i];
sum += cnt[i]*i;
for (int j = sum; j >= i; j--) {
for (int k = ; k <= cnt[i]; k++) {
if(j < k*i) break;
for (int l = k; l <= tot; l++) {
dp[l][j] = min(dp[l][j]+dp[l-k][j-k*i], );
}
}
}
dif++;
}
} if(dif <= ) return *printf("%d\n", n);
int ans = ;
for (int i = ; i < N; i++) {
if(cnt[i]) {
for (int j = ; j <= cnt[i]; j++) if(dp[j][j*i] == ) ans = max(ans, j);
}
}
printf("%d\n", ans);
return ;
}
Codeforces 1079 E - The Unbearable Lightness of Weights的更多相关文章
- Codeforces 1032 - A/B/C/D/E - (Undone)
链接:http://codeforces.com/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution
A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...
- Oracle操作XML各种场景介绍
版权声明:凭栏处.潇潇雨歇. https://blog.csdn.net/IndexMan/article/details/28130961 近期在研究Oracle PLSQL中对于XML的系列操作. ...
- [codeforces 339]C. Xenia and Weights
[codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
- CodeForces 489D Unbearable Controversy of Being (搜索)
Unbearable Controversy of Being 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/B Descrip ...
- codeforces 339C Xenia and Weights(dp或暴搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Weights Xenia has a set of weig ...
- CodeForces 489D Unbearable Controversy of Being (不知咋分类 思维题吧)
D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 256 megabytes ...
- CodeForces 489D Unbearable Controversy of Being
题意: 给出一个n个节点m条边的有向图,求如图所示的菱形的个数. 这四个节点必须直接相邻,菱形之间不区分节点b.d的个数. 分析: 我们枚举每个a和c,然后求出所有满足a邻接t且t邻接c的节点的个数记 ...
随机推荐
- Vue小案例 之 商品管理------批量删除与商品数量的调整
通过索引进行删除,进行测试,是否获取其索引: 测试效果: 测试代码,在vue中定义一个空的数组,以便后面进行数据的绑定: data:{ imgUrl:'../res/images/', imgName ...
- 深入浅出TCP之半关闭与CLOSE_WAIT
转自:https://www.2cto.com/net/201309/243585.html(相关链接) 深入浅出TCP之半关闭与CLOSE_WAIT 终止一个连接要经过4次握手.这由TCP的半关闭( ...
- 使用dockerfile构建自己的镜像
CentOS Linux release 7.2.1511 Docker version 17.03.1-ce 首先应该了解docker镜像的分层机制,这个网上文章很多,简单说就是对镜像的每次修改都是 ...
- Python带_的变量或函数命名
python中的标识符可以包含数字.字母和_,但必须以字母或者_开头,其中以_开头的命名一般具有特殊的意义. 前后均带有双下划线__的命名 一般用于特殊方法的命名,用来实现对象的一些行为或者功能,比如 ...
- You have new mail in /var/spool/mail/root
centos7.5 查看邮件的方式: [root@web01 code]# yum -y install mailx #安装mailx [root@web01 code]# mail #执行mail命 ...
- QML使用的内置对象
QML从ECMAScript继承而来,所以支持这个ECMAScript.经常在QML工程中看到Math.Data.....等方法,但是在Qt手册里搜索不到,这是因为这些方法不是QtQuick的,而是E ...
- topcoder srm 350 div1
problem1 link 满足$a^{b}\leq5000000,b>1$的数字不多,有2000多个,直接暴力计算能组成哪些数字即可. import java.util.*; import j ...
- js的原型prototype究竟是什么?
Javascript也是面向对象的语言,但它是一种基于原型Prototype的语言,而不是基于类的语言.在Javascript中,类和对象看起来没有太多的区别. 1.什么是prototype: fun ...
- Flask学习【第9篇】:Flask-script组件
Flask Script扩展提供向Flask插入外部脚本的功能,包括运行一个开发用的服务器,一个定制的Python shell,设置数据库的脚本,cronjobs,及其他运行在web应用之外的命令行任 ...
- CodeForces 430A Points and Segments (easy)(构造)题解
题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序 ...