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+暴力的更多相关文章
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dfs
D. Lizards and Basements 2 题目连接: http://codeforces.com/contest/6/problem/D Description This is simpl ...
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dp
题目链接: http://codeforces.com/problemset/problem/6/D D. Lizards and Basements 2 time limit per test2 s ...
- codeforces 6D
D. Lizards and Basements 2 time limit per test 2 seconds memory limit per test 64 megabytes input st ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- hdu 5612 Baby Ming and Matrix games(dfs暴力)
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...
- hdu 1010 Tempter of the Bone(dfs暴力)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- NOIP 2002提高组 选数 dfs/暴力
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...
随机推荐
- Spring boot基础:配置文件配置变量、多环境的配置
一.配置 resources下面application.properties 1.普通配置 resources下面application.properties,比如写上:server.port=909 ...
- Android制作曲线、柱状图、饼形等图表——使用AChartEngine
之前在java开发中实现图表使用JFreeChar组件,最近有个小项目要求在Android端进行数据分析,如何实现图表呢?查了一下google提供了一个开源组件Achartengine非常好用,可实现 ...
- 【翻译自mos文章】CRS显示 正在执行的db instance 是offline状态
CRS显示 正在执行的db instance 是offline状态 转自: CRS shows Running Instance Status as OFFLINE (Doc ID 1673397.1 ...
- IOS网络访问详解
第一.访问网络的方式 同步请求:数据的请求过程是由主线程发起的,网络加载需要一定的时间,因此会堵塞主线程 异步请求:数据的请求在多线程中完成 同步请求无法取消,异步请求的过程中可以取消,同步请求无法监 ...
- (转)Unity中protobuf的使用方法
在移动手机游戏开发中,目前Unity3D已成为比较主流的开发技术. 那么对于客户端服务器协议的打解包,我们有3中常用的处理方式: 1.自定义结构体:在协议中直接传输代码中自定义的结构体:这种方式的坏处 ...
- C++中用完需要释放掉内存的几个类
BSTR BSTR bstrXML = NULL; //用完以后,或者 catch段中 if(bstrXML) ::SysFreeString(result); VARIANT VARIANT v ...
- bash參考手冊之六(Bash特性)
6 Bash 特性 这部分描写叙述Bash独有的特性. * 调用Bash : Bash能够接受的命令行选项. * Bash启动文件 : Bash何时及怎样运行脚本. * 交互Shell : 什么 ...
- Bootstrap3实现的响应式幻灯滑动效果个人作品集/博客网站模板
在线演示 本地下载 如果你想学习如何开发和使用的话,请参考我们免费的课程: Bootstrap3开发滑动风格的博客网站模板
- IN 查询时出现ORA-01795:列表中的最大表达式数为1000解决方法
问题描写叙述: SQL进行IN查询时出现:java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000 解决的方法: 问题原因是:SQL进行IN查询时.IN中的 ...
- ubuntu 安装 codelite
http://www.linuxidc.com/Linux/2013-06/85332.htm Ubuntu 12.04下为codelite增添更新源 1.获取codelite的公钥 sudo apt ...