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的更多相关文章

  1. ZOJ 3631 Watashi's BG DFS

    J - Watashi's BG Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  2. [GodLove]Wine93 Tarining Round #3

    比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44857#overview 题目来源: ZOJ Monthly, July 2 ...

  3. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. ZOJ 3080 ChiBi(spfa)

    ZOJ Problem Set - 3080 ChiBi Time Limit: 5 Seconds      Memory Limit: 32768 KB watashi's mm is so pr ...

  6. ZOJ 3228 Searching the String(AC自动机)

    Searching the String Time Limit: 7 Seconds      Memory Limit: 129872 KB Little jay really hates to d ...

  7. ZOJ 3306 状压dp

    转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...

  8. ZOJ 3233 Lucky Number

    Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...

  9. zoj 3859 DoIt is Being Flooded (MFSet && Flood Fill)

    ZOJ :: Problems :: Show Problem 这题开始的时候想不到怎么调整每个grid的实际淹没时间,于是只好找了下watashi的题解,发现这个操作还是挺简单的. ZOJ3354 ...

随机推荐

  1. silverlight圆球滚动

    经大神启发后,才知道设置几个变量尤其是bool类型的方向,之后就是简单的判断了. // 当用户导航到此页面时执行. protected override void OnNavigatedTo(Navi ...

  2. php注册登录时生成的验证码

    http://blog.sina.com.cn/s/blog_8173443e01012l82.html 记得我学php时第一件事就是研究登陆注册.当然,登陆少不了验证码.两年过去了,昨天突然想用个验 ...

  3. oracle 11g不能连接报ORA-12537+ora-609解决

    操作系统: windows2008 数据库:oracle11g 问题发生:一套正常跑了一年的应用系统,忽然无法连接上数据库,但是另外一个应用可以正常链接,数据入库正常. 数据库服务器端查看: 使用 l ...

  4. 将Cell中的视图取出传递到根视图

    当我们点击Cell中的某个图片时,图片会有一种从Cell中取出,放大,然后再回到原来的Cell中的效果.我的想法是:当Cell中的图片用button 来显示.当我们点击Cell中的这个button的时 ...

  5. Linux消息队列

    #include <stdio.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/ms ...

  6. ubuntu 13.10自定义启动顺序

    添加PPA sudo add-apt-repository ppa:danielrichter2007/grub-customizer sudo apt-get update sudo apt-get ...

  7. ios 64位下编译webrtc的libvpx库出现错误Bad cputype for object file.Currently only tested for CPU_TYPE_x86_64

    diff --git a/libvpx.gyp b/libvpx.gypindex 4f8cb2b..4eb6866 100644--- a/libvpx.gyp+++ b/libvpx.gyp@@ ...

  8. (转)Libevent(1)— 简介、编译、配置

    转自:http://name5566.com/4190.html 参考文献列表:http://www.wangafu.net/~nickm/libevent-book/ 此文编写的时候,使用到的 Li ...

  9. spring mvc 和mybatis整合 的异常处理

    1.自定义异常信息类 通过构造函数来实现异常信息的接收 public class CustomException extends Exception { //异常信息 private String m ...

  10. 小笔记(三):PHP使用thinkphp3.2.3对数组进行分页

    之前写过thinkphp3.2.3直接在查询数据的时候进行分页,前段时间用到了将查询之后的数组进行整理后进行分页,用到的一个函数array_slice($arr, $start, $length,tr ...