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. js输出

    JavaScript 可以通过4种不同的方式在html页面输出数据 1.使用window.alert() 弹出警告框,由于window为js的内置类,可简写为alter() <script> ...

  2. P1290 欧几里德的游戏

    P1290 欧几里德的游戏 原本不想写的,但细节有些多qwq,还是放上吧. 假设a严格大于b 当a<b*2时,只有一种方法往下走:否则就可以有多种方法,并且一定至少有一种可以使自己必胜,因为可以 ...

  3. k8s debug

    https://feisky.gitbooks.io/kubernetes/components/api-aggregation.html API convention Kubernetes deep ...

  4. charles最新破解jar文件,及浏览器证书安装

    一 在线破解文件下载 Charles 在线破解工具,https://www.zzzmode.com/mytools/charles/ 描述 此工具用于生成破解后的charles.jar文件,  破解原 ...

  5. rman备份例子

    1.全备份例子 #!/bin/sh RMAN_OUTPUT_LOG=/home/oracle/rman_output.logRMAN_ERROR_LOG=/home/oracle/rman_error ...

  6. 20145320《WEB基础实践》

    20145320WEB基础实践 实验问题回答 1.什么是表单 表单可以收集用户的信息和反馈意见,是网站管理者与浏览者之间沟通的桥梁. 一个表单有三个基本组成部分: 表单标签 表单域:包含了文本框.密码 ...

  7. bzoj 4318 OSU! - 动态规划 - 概率与期望

    Description osu 是一款群众喜闻乐见的休闲软件.  我们可以把osu的规则简化与改编成以下的样子:  一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1 ...

  8. Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

    Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations ...

  9. Junit 的Assertions的使用

    import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.anyOf; import ...

  10. 重要, 要播放音乐视频等多媒体: 安装fedora23中的多媒体编码器

    区分: 大多数用户和高级用户? 删除 dnf remove software-name 启动软件管理器: gnome-software. 要删除系统 "自带的" 软件, 如empt ...