[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 ...
随机推荐
- Servlet相关接口和Servlet的生命周期
http://www.cnblogs.com/luotaoyeah/p/3860292.html Servlet相关接口和Servlet的生命周期 创建一个Servlet类最直接的方式是实现javax ...
- Virtual Studio C++ Version Macro - _MSC_VER
MSVC++ (Visual Studio ) MSVC++ (Visual Studio ) MSVC++ (Visual Studio ) MSVC++ (Visual Studio ) MSVC ...
- JS模版引擎[20行代码实现模版引擎读后感]
曾经阅读过<只有20行JAVASCRIPT代码, 手把手教你写一个页面模版引擎>这篇文章, 对其中实现模版的想法实在膜拜, 于是有了这篇读后感, 谈谈自己对模版引擎的理解, 以及用自己的语 ...
- (hdu)5547 Sudoku (4*4方格的 数独 深搜)
Problem Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game ...
- nodejs 实现机制
最近在学习nodejs,作为一个从未学过javascript的程序员,把自己学习的过程贴出来,当做记录和总结吧. 1. nodejs的原理: nodejs完全是基于事件轮询机制的一个javascrip ...
- EntityClient 介绍
System.Data.EntityClient 命名空间是 实体框架的 .NET Framework 数据提供程序.EntityClient 提供程序使用存储特定的 ADO.NET 数据提供程序类和 ...
- 处理safari缓存的办法
window.onpageshow = function(event) { if (event.persisted) { alert("From bac ...
- WPF 得一些问题汇总
1.CallMethodAction <TextBox Height="30" Name="txtUserName" Width="160&qu ...
- (转载)delphi 把图片存入数据库
delphi 把图片存入数据库 procedure TForm1.Button1Click(Sender: TObject); // 插入图片过程var Stream:TMemoryStream;be ...
- 简单vim配置
对于一个学习C++的人来说,我常用VS写代码,而Linux环境也是很重要的.最近学习了Linux的一些基本内容后,开始了vim编辑器的使用.然而它刚开始的界面着实令人很不习惯~~~于是我尝试着把它装饰 ...