POJ 1015
#include<iostream>
#include<algorithm>
#define MAXN 201
#define count C_ount
using namespace std; int _m[][];
int count[][];
int a[]; struct _node
{
int first;
int second;
}; _node _cand[MAXN];
int n;
int main()
{
//freopen("acm.acm","r",stdin);
int m;
int i;
int j;
int time;
int max;
int u;
int v;
int u_v;
int _i;
int _j;
int _test_time = ;
int index;
int ans;
while(cin>>n>>m,n||m)
{
memset(count,-,sizeof(count));
memset(_m,-,sizeof(_m));
max = m*;
for(i = ; i < n; ++ i)
{
cin>>u>>v;
_cand[i].first = u - v;
_cand[i].second = u + v;
}
for(i = ; i < n; ++ i)
{
if(count[][max+_cand[i].first] < _cand[i].second)
{
_m[][max+_cand[i].first] = i;
count[][max+_cand[i].first] = _cand[i].second;
}
}
for(time = ; time < m-; ++ time)
{
for(u_v = ; u_v <= max*; ++ u_v)
{
if(_m[time][u_v] != -)
{
for(i = ; i < n; ++ i)
{
if(count[time+][u_v + _cand[i].first] < count[time][u_v] + _cand[i].second)
{
_j = u_v;
for(_i = time; _i >= ; -- _i)
{
if(_m[_i][_j] == i)
break;
_j -= _cand[_m[_i][_j]].first;
}
if(_i < )
{
_m[time+][u_v+_cand[i].first] = i;
count[time+][u_v+_cand[i].first] = count[time][u_v] + _cand[i].second;
}
}
}
}
}
} ///////////// for(i = ; i <= max; ++ i)
{
int tem_1 = count[m-][max+i];
int tem_2 = count[m-][max-i];
if( (tem_1 = count[m-][max+i]) >= || (tem_2 = count[m-][max-i]) >= )
{
if(tem_1 > tem_2)
{
ans = max+i;
}
else
{
ans = max-i;
}
break;
}
}
cout<<"Jury #"<<++ _test_time<<endl;
cout<<"Best jury has value "<<(count[m-][ans] + (ans - max))/<<" for prosecution and value "<<(count[m-][ans] - (ans - max))/<<" for defence:"<<endl;
j = ans;
index = ;
for(i = m-; i >= ; -- i)
{
a[index ++] = _m[i][j];
j -= _cand[_m[i][j]].first;
}
sort(a,a+index);
for(i = ; i < index; ++ i)
{
cout<<" "<<a[i]+;
}
cout<<endl;
cout<<endl;
}
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1015的更多相关文章
- OpenJudge 2979 陪审团的人选 / Poj 1015 Jury Compromise
1.链接地址: http://bailian.openjudge.cn/practice/2979 http://poj.org/problem?id=1015 2.题目: 总Time Limit: ...
- 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)
作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...
- POJ 1015 Jury Compromise 2个月后重做,其实这是背包题目
http://poj.org/problem?id=1015 题目大意:在遥远的国家佛罗布尼亚,嫌犯是否有罪,须由陪审团决定.陪审团是由法官从公众中挑选的.先随机挑选n个人作为陪审团的候选人,然后再从 ...
- (最优m个候选人 和他们的编号)Jury Compromise (POJ 1015) 难
http://poj.org/problem?id=1015 Description In Frobnia, a far-away country, the verdicts in court t ...
- POJ 1015 Jury Compromise dp分组
第一次做dp分组的问题,百度的~~ http://poj.org/problem?id=1015 题目大意:在遥远的国家佛罗布尼亚,嫌犯是否有罪,须由陪审团决定.陪审团是由法官从公众中挑选的.先随机挑 ...
- [Poj 1015] Jury Compromise 解题报告 (完全背包)
题目链接:http://poj.org/problem?id=1015 题目: 题解: 我们考虑设计DP状态(因为这很显然是一个完全背包问题不是吗?) dp[j][k]表示在外层循环到i时,选了j个人 ...
- POJ #1015 - Jury Compromise - TODO: POJ website issue
(poj.org issue. Not submitted yet) This is a 2D DP problem, very classic too. Since I'm just learnin ...
- Jury Compromise POJ - 1015 dp (标答有误)背包思想
题意:从 n个人里面找到m个人 每个人有两个值 d p 满足在abs(sum(d)-sum(p)) 最小的前提下sum(d)+sum(p)最大 思路:dp[i][j] i个人中 和 ...
- HDU POJ 1015 Jury Compromise(陪审团的人选,DP)
题意: 在遥远的国家佛罗布尼亚,嫌犯是否有罪,须由陪审团决定.陪审团是由法官从公众中挑选的.先随机挑选n个人作为陪审团的候选人,然后再从这n个人中选m人组成陪审团.选m人的办法是:控方和辩方会根据对候 ...
- poj 1015 Jury Compromise_dp
题意:n个陪审团,每个陪审团有x,y值,选出m个陪审团,要求 (sum(xi)-sum(yi))最少,当 (sum(xi)-sum(yi))最少有多个,取sum(xi)+sum(yi)最大那个 ,并顺 ...
随机推荐
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- 2018.09.07 bzoj1911: [Apio2010]特别行动队(斜率优化dp)
传送门 斜率优化dp经典题. 题目中说的很清楚,设f[i]表示前i个数分配出的最大值. 那么有: f[i]=max(f[j]+A∗(sum[i]−sum[j])2+B∗(sum[i]−sum[j])+ ...
- Android 6.0以上 需要运行时申请的权限
转载:http://www.cnblogs.com/tangs/articles/6377347.html 自从Android6.0发布以来,在权限上做出了很大的变动,不再是之前的只要在manifes ...
- UVa 11248 Frequency Hopping (网络流)
题意:给定上一个网络,每个边有一个容量,问你能不能从 1 到 n,使得流量为 c,如果不能,那么是不是可以修改一条边,使得达到. 析:背景就是一个网络流,如果原图能跑出来,那么就不用了,就肯定能达到, ...
- python网页爬虫 spiders_97A-04B
import urllib import urllib.request import bs4 from bs4 import BeautifulSoup as bs import re import ...
- spring @Transactional 声明式事务
项目地址:git@github.com:witaste/transaction-annotation.git 情景一: A external method calls a method of the ...
- 高翔《视觉SLAM十四讲》从理论到实践
目录 第1讲 前言:本书讲什么:如何使用本书: 第2讲 初始SLAM:引子-小萝卜的例子:经典视觉SLAM框架:SLAM问题的数学表述:实践-编程基础: 第3讲 三维空间刚体运动 旋转矩阵:实践-Ei ...
- (深搜)Sum It Up -- poj --1564
链接: http://poj.org/problem?id=1564 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...
- Lucene 中自定义排序的实现
使用Lucene来搜索内容,搜索结果的显示顺序当然是比较重要的.Lucene中Build-in的几个排序定义在大多数情况下是不适合我们使用的.要适合自己的应用程序的场景,就只能自定义排序功能,本节我们 ...
- 逆着得最长路POJ1797
POJ1797点击打开链接 这个题很是不错我感觉 很容易把这个题和上一个青蛙跳的题联系起来做,我也确实联系起来了,可还是没能完整得Ac,是因为我的算法思路还是最短路,这里错了 这个题目得要求是,从1到 ...