[ZOJ 3631] Watashi's BG
Watashi's BG
Time Limit: 3 Seconds Memory Limit: 65536 KB
Watashi is the couch of ZJU-ICPC Team and he is very kind hearted. In ZJU-ICPC summer training camp, students are divided into several groups and each day one of the groups will design some problems to hold a contest. Today students of Group C are required to design the problems, and they spent the whole night to check to test data which made them very tired. Watashi decides to give some money as a reward to group C so that they can buy the lunch for free.
There are N days in the training schedule, and all students have booked their lunch for N days so we know how much money they will spend in each day. Now the leader of group C needs to decide how to use Watashi's money. Since the money is limited, it may not be possible that they can have free lunch every day. So each day the leader can choose to pay for the whole group's lunch by themselves or use Watashi's money. Of course, the leader wants to spend Watashi's money as much as possible, but he is too busy to write a program to calculate the maximum money he can spend from Watashi's reward. Can you help him?
Input
The input contains multiple test cases ( no more than 50 test cases ). In each test case, first there are two integer, N ( 1 <= N <=30 ) , which is the number of training days, M ( 0 <= M <=10000000 ) , which is the reward money from Watashi. Then there is a line containing N positive integers with the ith integer indicating the money group C need to pay for the lunch of the ith day. All these integers are no more than 10000000 and integers are seperated by a space.
Output
For each test case, output one line with an integer which is the maximum money group C can spend from Watashi's reward
Sample Input
3 10
8 4 5
Sample Output
9
剪枝很重要!!!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 33 int n,m;
int ans;
int a[N];
int sum[N]; bool cmp(int a,int b){ return a>b;} void DFS(int nowx,int nows)
{
if(nows>m) return;
if(nowx>=n)
{
ans=max(nows,ans);
return;
}
if(nows+sum[n-]-sum[nowx-]<ans) return;
DFS(nowx+,nows+a[nowx]);
DFS(nowx+,nows);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n,cmp);
for(int i=;i<n;i++)
{
if(i==) sum[i]=;
else sum[i]=sum[i-]+a[i];
}
ans=;
DFS(,);
printf("%d\n",ans);
}
return ;
}
[ZOJ 3631] Watashi's BG的更多相关文章
- ZOJ 3631 Watashi's BG DFS
J - Watashi's BG Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- [GodLove]Wine93 Tarining Round #3
比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44857#overview 题目来源: ZOJ Monthly, July 2 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ 3080 ChiBi(spfa)
ZOJ Problem Set - 3080 ChiBi Time Limit: 5 Seconds Memory Limit: 32768 KB watashi's mm is so pr ...
- ZOJ 3228 Searching the String(AC自动机)
Searching the String Time Limit: 7 Seconds Memory Limit: 129872 KB Little jay really hates to d ...
- ZOJ 3306 状压dp
转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...
- ZOJ 3233 Lucky Number
Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- zoj 3859 DoIt is Being Flooded (MFSet && Flood Fill)
ZOJ :: Problems :: Show Problem 这题开始的时候想不到怎么调整每个grid的实际淹没时间,于是只好找了下watashi的题解,发现这个操作还是挺简单的. ZOJ3354 ...
随机推荐
- 学习笔记_Java_day14—编码实战___一个注册页面的完整流程
- 学习笔记6_Java_day11_JSP_基础和入门(1、2)
主要内容:1. JSP基础2. Cookie3. HttpSession ================================ JSP基础 1. jsp的作用: * Servlet: &g ...
- cordova安装中的坑
1.安装android环境直接略过! 2.安装node.js直接略过! 3.安装cordova npm install -g cordova npm uninstall cordova -g(这条是 ...
- 11_关于SqlMapperConfig.xml
[简述] SqlMapConfig.xml是Mybatis的全局配置文件,配置内容如下: 1.properties---------属性 2.settings-----------全局配置参数 3.t ...
- OpenJudge 1806:词典find()与end()
1806:词典 总时间限制: 3000ms 内存限制: 65536kB 描述 你旅游到了一个国外的城市.那里的人们说的外国语言你不能理解.不过幸运的是,你有一本词典可以帮助你. 输入 首先输入一 ...
- 暑假集训(2)第九弹 ----- Points on Cycle(hdu1700)
Points on Cycle Time Limit:1000MS Memory Limit:32768 ...
- ubuntn svn 安装 配置
参考文章 http://zhan.renren.com/itbegin?gid=3602888498033631485&checked=true 上面的文章说得很详细 sudo apt-ge ...
- 深度学习算法实践15---堆叠去噪自动编码机(SdA)原理及实现
我们讨论了去噪自动编码机(dA),并讨论了Theano框架实现的细节.在本节中,我们将讨论去噪自动编码机(dA)的主要应用,即组成堆叠自动编码机(SdA),我们将以MNIST手写字母识别为例,用堆叠自 ...
- Spring Cloud Eureka Server 启停状态监控
目前发现如下的api: 当时没有找到文档 http://localhost:8761/eureka/apps 参考文章:(此文中api带有v2我自己试验不需要v2) http://blog.csdn. ...
- $(window)和$(document)
注意:本次测试采用的jquery1.9.1的版本 1. $(window).scrollTop() 和$(document).scrollTop()得出的结果是一样的 2. $(window).h ...