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

  1. Codeforces 1032 - A/B/C/D/E - (Undone)

    链接:http://codeforces.com/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题 ...

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

  3. Oracle操作XML各种场景介绍

    版权声明:凭栏处.潇潇雨歇. https://blog.csdn.net/IndexMan/article/details/28130961 近期在研究Oracle PLSQL中对于XML的系列操作. ...

  4. [codeforces 339]C. Xenia and Weights

    [codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...

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

  6. CodeForces 489D Unbearable Controversy of Being (搜索)

    Unbearable Controversy of Being 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/B Descrip ...

  7. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  8. CodeForces 489D Unbearable Controversy of Being (不知咋分类 思维题吧)

    D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 256 megabytes ...

  9. CodeForces 489D Unbearable Controversy of Being

    题意: 给出一个n个节点m条边的有向图,求如图所示的菱形的个数. 这四个节点必须直接相邻,菱形之间不区分节点b.d的个数. 分析: 我们枚举每个a和c,然后求出所有满足a邻接t且t邻接c的节点的个数记 ...

随机推荐

  1. P3332 [ZJOI2013]K大数查询(线段树套线段树+标记永久化)

    P3332 [ZJOI2013]K大数查询 权值线段树套区间线段树 把插入的值离散化一下开个线段树 蓝后每个节点开个线段树,维护一下每个数出现的区间和次数 为了防止MLE动态开点就好辣 重点是标记永久 ...

  2. TCP/IP 最常见的错误原因码 (errno)列表

    对于在基于 UNIX 的环境中的 TCP/IP 用户,下表列出了某些最常见的错误原因码 (errno).它不是完整的错误列表.可以在文件 /usr/include/sys/errno.h 中找到 Er ...

  3. suse日常操作(含suse/rhel内核与发行版对应关系)

    最近有家客户要求只能使用suse系统,是suse 12 sp3的,而且版本都不同意换,一直以来,都是使用rhel的客户,还没遇到过suse的,可偏偏不巧,我们的系统和suse 12 sp3自带的gli ...

  4. rabbitmq集群安装与配置(故障恢复)

    0.首先按照http://www.cnblogs.com/zhjh256/p/5922562.html在至少两个节点安装好(不建议单机,没什么意义) 1.先了解rabbitmq集群架构,http:// ...

  5. 让CSS某行不失效

    比如百度的分享代码 <div id="bdshare" class="bdshare_t bds_tools get-codes-bdshare"> ...

  6. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165211

    目录 软件和镜像下载 虚拟机软件 Kali系统的下载 Kali系统安装 网络配置 设置共享文件夹和剪切板 安装VMware增强工具 设置共享文件夹 设置共享剪切板 更新软件源 软件和镜像下载 虚拟机软 ...

  7. bzoj 2844 albus就是要第一个出场 - 线性基

    题目传送门 这是个通往vjudge的虫洞 这是个通往bzoj的虫洞 题目大意 给定集合$S$,现在将任意$A\subseteq S$中的元素求异或和,然后存入一个数组中(下标从1开始),然后从小到大排 ...

  8. VC++ 使用ShellExecute函数调用邮箱客户端发送邮件(可以带附件)

      之前写过一篇博文,通过MAPI实现调用邮箱客户端发送邮件带附件,当时对ShellExecute研究不深,以为ShellExecute不能带附件,因为项目需求原因(MAPI只能调用Foxmail和O ...

  9. oracle数据库数据库表空间查询及扩充

    1.查询表空间,及表空间的大小 SELECT t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size FROM dba_tabl ...

  10. 三星固态sm863,pm863,sm865,sm865a颗粒

    目录 左pm863,右sm863: sm865: sm865a: 主控,缓存: 颗粒: 左pm863,右sm863: sm865: sm865a: 主控,缓存: 颗粒: