zojDakar Rally(01背包)
01背包 加上每次更新解题数目最多 总用时最少 因为要保证用时最少,要先把时长由小到大排序。
没排序 WA了几小时。。链接
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define N 1010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int dp[N*][];
struct node
{
int ti,v;
}p[N];
bool cmp(node x,node y)
{
return x.ti<y.ti;
}
int main()
{
int i,j,t,n,nn;
cin>>nn;
while(nn--)
{
memset(dp,,sizeof(dp));
cin>>t>>n;
for(i = ; i <= n; i++)
cin>>p[i].ti;
for(i = ; i <= n; i++)
cin>>p[i].v;
sort(p+,p+n+,cmp);
for(i = ; i <= n ; i++)
{
for(j = t ; j >= p[i].ti ; j--)
{
if(dp[j-p[i].ti][]+p[i].v>dp[j][])
{
dp[j][] = dp[j-p[i].ti][]+p[i].v;
dp[j][] = dp[j-p[i].ti][]+;
dp[j][] = dp[j-p[i].ti][]+j;
}
else if(dp[j-p[i].ti][]+p[i].v==dp[j][]&&dp[j-p[i].ti][]+>=dp[j][])
{
if(dp[j-p[i].ti][]+>dp[j][]||dp[j][]>dp[j-p[i].ti][]+j)
{
dp[j][] = dp[j-p[i].ti][]+p[i].v;
dp[j][] = dp[j-p[i].ti][]+;
dp[j][] = dp[j-p[i].ti][]+j;
}
}
}
}
int ans = ,x=,y=;
for(i = t ; i >= ;i--)
{
if(dp[i][]>=ans)
{
if(dp[i][]==ans&&dp[i][]>=x)
{
if(dp[i][]>x||dp[i][]<y)
{
ans = dp[i][];
x = dp[i][];
y = dp[i][];
}
}
if(dp[i][]>ans)
{
ans = dp[i][];
x = dp[i][];
y = dp[i][];
}
}
}
cout<<ans<<" "<<x<<" "<<y<<endl;
}
return ;
}
zojDakar Rally(01背包)的更多相关文章
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- 51nod1085(01背包)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...
- *HDU3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)
题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
- hdu3339 In Action(Dijkstra+01背包)
/* 题意:有 n 个站点(编号1...n),每一个站点都有一个能量值,为了不让这些能量值连接起来,要用 坦克占领这个站点!已知站点的 之间的距离,每个坦克从0点出发到某一个站点,1 unit dis ...
随机推荐
- Zookeeper 简单操作
1. 连接到zookeeper服务 [java2000_wl@localhost zookeeper-3]$ bin/zkCli.sh -server 127.0.0.1:2181 也可以连接远端的 ...
- soapUI系列之—-02 Groovy脚本常用方法
------Groovy脚本常用方法 1. 设置参数值:setPropertyValuea. 设置 project level property//set to project level prope ...
- 【转载】HTTP协议与WEB本质
当你在浏览器地址栏敲入"http://www.csdn.net/",然后猛按回车,呈现在你面前的,将是csdn的首页了(这真是废话,你会认为这是理所当然的).作为一个开发者,尤其是 ...
- Android中View窗口getWidth和getMeasuredWidth的差别
今天在研究自己定义listview的下拉刷新的效果.想移植到项目需求中,再看自己定义源代码时发现了一个问题就是getWidth和getMeasuredWidth两个方法有什么差别,求教万能的百度,经调 ...
- iOS开发——高级篇——线程保活
线程保活: 顾名思义,就是保护线程不死(保证线程处于激活状态,生命周期没有结束) 正常情况,当线程执行完一次任务之后,需要进行资源回收,也就意味着生命周期结束 应用场景: 当有一个任务,随时都有可能去 ...
- Educational Codeforces Round 18 C. Divide by Three DP
C. Divide by Three A positive integer number n is written on a blackboard. It consists of not more ...
- 【bzoj2753】[SCOI2012]滑雪与时间胶囊
#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> # ...
- 【转】WdatePicker.js的使用方法 帮助文档 使用说明 如何使用
[转]WdatePicker.js的使用方法 帮助文档 使用说明 如何使用 日期控件支持平面显示功能,只要设置一下eCont属性就可以把它当作日历来使用了,无需触发条件,直接显示在页面上 示例2-1 ...
- I.MX6 逻辑分析仪 UART
/*********************************************************************** * I.MX6 逻辑分析仪 UART * 说明: * ...
- AutoIT: 开发界面结合GUI automation和Watir Automation
可以应用AutoIT开发出界面,从而把AutoIT对GUI的自动化测试与Watir对web的自动化测结合在一起.以下代码是我学习GUI界面开发的实例代码.1. 当点击Watir_Test_Button ...