Codeforces 6D Lizards and Basements 2 dfs+暴力

题目链接:点击打开链接

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 110
#define ll int

ll n, a, b;
ll h[N];
vector<int>G,ans;
void dfs(int u, bool hehe){//hehe=true表示u-1没死
	if(u==n && hehe==false){
		if(G.size()<ans.size())
			ans = G;
		return ;
	}
	int siz = 0;
	if(hehe) {
		while(h[u-1]>0)siz++,h[u-1]-=b, h[u]-=a, h[u+1]-=b, G.push_back(u);
	}
	if(h[u]>0) {
		while(h[u]>0) {
			dfs(u+1,true);
			h[u-1]-=b;
			h[u]-=a;
			h[u+1]-=b;
			siz++;
			G.push_back(u);
		}
	}
	dfs(u+1,false);
	h[u]+=a*siz;
	h[u+1]+=b*siz;
	h[u-1]+=b*siz;
	while(siz--)G.erase(G.end()-1);
}
int main(){
	ll i, j;
	while(~scanf("%d %d %d",&n,&a,&b)){
		G.clear(); ans.clear();
		for(i=1;i<=n;i++)scanf("%d",&h[i]), h[i]++;
		while(h[1]>0){
			h[2] -= a;
			h[1] -= b;
			h[3] -= b;
			ans.push_back(2);
		}
		while(h[n]>0){
			h[n-2] -= b;
			h[n-1] -= a;
			h[n] -= b;
			ans.push_back(n-1);
		}
		G = ans;
		for(i=1;i<=100;i++)ans.push_back(i);
		dfs(2,false);
		printf("%d\n",ans.size());
		for(i = 0; i < ans.size(); i++)printf("%d%c",ans[i],i==ans.size()-1?'\n':' ');
	}
	return 0;
}

/**/

Codeforces 6D Lizards and Basements 2 dfs+暴力,布布扣,bubuko.com

时间: 2024-10-28 10:29:31

Codeforces 6D Lizards and Basements 2 dfs+暴力的相关文章

CodeForces 6D Lizards and Basements 2

算是简单DP了,一开始竟没看出来,醉了. 首先,对于当前位置site,需知道site-1处丢了pre个,site处丢了now个火球,然后枚举site+1处的情况. #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <cmath>

Codeforces Round #286 (Div. 2)B. Mr. Kitayuta&#39;s Colorful Graph(dfs,暴力)

数据规模小,所以就暴力枚举每一种颜色的边就行了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm>

hdu 5024 Wang Xifeng&#39;s Little Plot (dfs+暴力)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 131 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

ACM: Gym 100935G Board Game - DFS暴力搜索

Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 100935G Description standard input/outputStatements Feras bought to his nephew Saleem a new game to help him learning calculating. The game consists of a boar

NOIP 2002提高组 选数 dfs/暴力

1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合与它们的和为: 3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34. 现在,要求你计算出和为素

ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Practice Description Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle

hdu1015 dfs暴力搜索所有情况模板

脑子有点坑,不知道为什么,可能以前遇到阴影了,现在看到dfs暴力搜有种莫名的害怕,总结一下模板吧 这题还是没意思的,直接暴力搜,不过我写的很烂,可能就是这个原因吧,看了别人的模板,觉得不错. 学了个单词”lexicography“ 字典序,又吃了没文化的亏,wa一次 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath>

CodeForces 440C One-Based Arithmetic(递归,dfs)

A - One-Based Arithmetic Time Limit:500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2014-08-21) Description Prof. Vasechkin wants to represent positive integer n as a sum of adden

Codeforces 451C Predict Outcome of the Game(暴力)

题目连接:Codeforces 451C Predict Outcome of the Game 题目大意:题意有点坑,就是三支球队有n场比赛,错过了k场,即这k场比赛不知道输赢,只知道第一支球队和第二支球队胜局情况差d1,第二和第三差d2,问说最后有没有可能三支队伍胜局数相同. 解题思路:考虑四种情况下的场数u,是否为3的倍数,u/3后是否比当前情况下胜局数最高的队伍大,并且还要判断该情况是否可行. #include <cstdio> #include <cstring> #in