ZOJ 3631-Watashi's BG(bfs+循环队列)

原创 2015年11月20日 13:18:24
A - Watashi's BG
Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
Appoint description: 


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?


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 ithday. All these integers are no more than 10000000 and integers are seperated by a space.


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




typedef long long ll;
using namespace std;
#define T 8000000
#define inf 0x3f3f3f3f
int n,m;
int v[35];
struct node
	int i;
	int v;
	node(int _i,int _v):i(_i),v(_v){}
node q[T];
int head,tail;
int bfs()
	int ma =0;
		p = q[(head++)%T];
		if(p.v==m)return m;
		for(int i=p.i+1;i<n;++i){
			if(p.v+v[i]==m)return m;
			q[(tail++)%T] = node(i,p.v+v[i]);
	return ma;
int main()
#ifdef zsc
	 head =tail = 0;
	 for(int i=0;i<n;++i){
	 for(int i=0;i<n;++i){
		 p.v = v[i];
		 p.i = i;
		q[tail++] = p;
    return 0;

版权声明:本文为博主原创文章,转载必须声明出处,thank。 https://blog.csdn.net/zsc2014030403015/article/details/49946067


  • gotowu
  • gotowu
  • 2015年11月25日 21:51
  • 705

hdoj.1881 毕业bg【DP】 2015/03/26

毕业bg Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total...
  • hdweilao
  • hdweilao
  • 2015年03月26日 19:34
  • 109

zoj-3947-Very Happy Great BG

The summer training of ZJU ICPC in July is about to end. To celebrate this great and happy day, the ...
  • Ypopstar
  • Ypopstar
  • 2016年04月24日 21:05
  • 150

zoj 3631 Watashi's BG

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4777   题目大意: 有n(1~30)天,第i天花费vi(1~...
  • gotoac
  • gotoac
  • 2013年04月17日 12:20
  • 497

ZOJ 3631 Watashi's BG

DFS + 诡异的剪枝
  • H992109898
  • H992109898
  • 2016年03月11日 15:42
  • 186


#include #include #define MAXSIZE 50 typedef struct { int element[MAXSIZE]; int front; //...
  • potential1
  • potential1
  • 2017年05月21日 18:32
  • 753

ZOJ 3631 Watashi's BG(双向枚举)

Watashi's BG Time Limit: 3 Seconds      Memory Limit: 65536 KB Watashi is the couch of ZJU-ICP...
  • acm_BaiHuzi
  • acm_BaiHuzi
  • 2015年07月21日 00:25
  • 535

【斐波拉契+数论+同余】【ZOJ3707】Calculate Prime S

题目大意: S[n] 表示 集合{1,2,3,4,5.......n} 不存在连续元素的子集个数 Prime S 表示S[n]与之前的所有S[i]互质; 问 找到大于第K个PrimeS 能整除X ...
  • zy691357966
  • zy691357966
  • 2015年04月03日 17:45
  • 1161

ZOJ 3631 Watashi's BG(DFS)

普通的0/1背包超时.只能用搜索. 剪枝: 首先对价格从大到小排序 当前的和加上剩余的价格和如果小于等最优值,那么就剪掉,因为结果肯定小于等于最优值 #include #include ...
  • zxjcarrot
  • zxjcarrot
  • 2013年04月25日 23:25
  • 341

zoj - 3631 - Watashi's BG(dfs)

题意:N天钱序列,最大报销额为M,对于其中的一天可选择报不不报,问最多能报销多少钱。(每天的钱不可拆分)(1 题目链接:http://acm.zju.edu.cn/onlinejudge/showP...
  • SCNU_Jiechao
  • SCNU_Jiechao
  • 2013年05月27日 12:58
  • 791
您举报文章:ZOJ 3631-Watashi's BG(bfs+循环队列)