BZOJ1334:[Baltic2008]Elect(背包DP)
Description
Input
Output
你的组阁方案中最多能占多少个席位.
Sample Input
1 3 2 4
Sample Output
//选择第二个政党和第四个
Solution
Code
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N (100009)
using namespace std; int n,sum,f[N],a[N]; int main()
{
scanf("%d",&n);
for (int i=; i<=n; ++i)
scanf("%d",&a[i]),sum+=a[i];
sort(a+,a+n+);
f[]=;
for (int i=n; i>=; --i)
for (int j=min(sum,sum/+a[i]); j>=a[i]; --j)
f[j]|=f[j-a[i]];
for (int i=sum; i>sum/; --i)
if (f[i]) {printf("%d\n",i); return ;}
puts("");
}
BZOJ1334:[Baltic2008]Elect(背包DP)的更多相关文章
- 【bzoj1334】[Baltic2008]Elect 背包dp
题目描述 N个政党要组成一个联合内阁,每个党都有自己的席位数. 现在希望你找出一种方案,你选中的党的席位数要大于总数的一半,并且联合内阁的席位数越多越好. 对于一个联合内阁,如果某个政党退出后,其它党 ...
- BZOJ1334: [Baltic2008]Elect
1334: [Baltic2008]Elect Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 386 Solved: 201[Submit][Sta ...
- [BOI2008] Elect - 背包dp
u1s1我一开始理解错了题 然后基本就相当于一个背包dp了 #include <bits/stdc++.h> using namespace std; int n,tot,a[305],f ...
- 【贪心+背包】BZOJ1334 [Baltic2008]Elect
Description 从N个数中选出任意个数且和尽量大,但要满足去掉任意一个和就小于总和的一半.n<=300, ai<=1e5. Solution 这个条件其实就是 去掉选出的最小的一个 ...
- 背包dp整理
01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 5501 The Highest Mark 背包dp
The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- noj [1479] How many (01背包||DP||DFS)
http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...
随机推荐
- windows上memecache添加多个端口命令
sc create "Memcached Server1" start= auto binPath= "D:\01_Soft\memcached\memcached.ex ...
- poj 3104 dring 二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7684 Accepted: 1967 Descriptio ...
- java poi处理新版xlsx后缀的excel
jar包下载地址http://poi.apache.org/download.html#POI-3.17,我把下载文件中的所有jar包都导入项目中才能跑 参考以下博客 https://www.cnbl ...
- linux ssh免密登陆
大致流程: 两台linux系统A B 如果A要登陆到B 1.生成A的密钥对 2.将A的公钥拷贝到B的authorized_keys中即可 可以使用命令:ssh-copy-id -i ~/.ssh/id ...
- Redis ,Memcached ,Mongodb 对比
memcached: 1.适合做内存缓存,对可靠性没有要求,不支持持久化:速度快.并发高.2.支持的数据结构单一,只支持Key-value,3.value最大支持1M3.在传统tomcat 部署war ...
- POJ P2777 Count Color——线段树状态压缩
Description Chosen Problem Solving and Program design as an optional course, you are required to sol ...
- 洛谷 P3391 文艺平衡树
题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 4 1 --b ...
- JavaWeb学习总结(一):基本概念
一.基本概念 1.1.WEB开发的相关知识 WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. Internet上供外界访问的Web资源分为: 静态web资源( ...
- Leetcode算法比赛----Longest Absolute File Path
问题描述 Suppose we abstract our file system by a string in the following manner: The string "dir\n ...
- Android中使用异步线程更新UI视图的几种方法
在Android中子线程是不能更新ui的. 所以我们要通过其他方式来动态改变ui视图, 1.runOnUiThreadactivity提供的一个轻量级更新ui的方法,在Fragment需要使用的时候要 ...