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 ...
随机推荐
- Spark性能优化(2)——广播变量、本地缓存目录、RDD操作、数据倾斜
广播变量 背景 一般Task大小超过10K时(Spark官方建议是20K),需要考虑使用广播变量进行优化.大表小表Join,小表使用广播的方式,减少Join操作. 参考:Spark广播变量与累加器 L ...
- python 插入数据获取id
python 插入数据获取id 学习了:https://blog.csdn.net/qq_37788558/article/details/78151972 commit之前获取 cursor.las ...
- [Node.js]25. Level 5. Route params
Create a route that responds to a GET request '/quotes/<name>', then use the param from the UR ...
- C#.NET常见问题(FAQ)-listView如何显示网格线
把GridLines设置为True 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai123 我的在线论坛: http:/ ...
- Electron 调用系统Office软件
通过打开本地空白文件的方式从而打开Office办公软件 const shell = require('electron').shell; const path = require('path'); s ...
- #define中的“#”和“##”的作用
在#define中,标准只定义了#和##两种操作: #用来把参数转换成字符串: ##则用来连接两个前后两个参数,把它们变成一个字符串.
- TCP相关面试题总结
1.TCP三次握手过程 wireshark抓包为:(wireshark会将seq序号和ACK自己主动显示为相对值) 1)主机A发送标志syn=1,随机产生seq =1234567的数据包到server ...
- MISRA-C 2012 C90规范和C99规范对比
- SQL 2008 R2数据库变为REPLICATION,日志不断增长并且不能截断和收缩的解决方式
执行环境:windows server2003,sql server2008 R2,数据库上布置CDC 用户反应系统报错是日志已满,系统不能执行. 查看日志文件时.发现日志文件已经达到15G ...
- Servlet介绍(一)
Servlet介绍(一) Servlet是一个执行在webserver上的小的Java程序,它通过接收和响应webclient的请求.在tomcatserver中有已经帮我们实现好了Servlet接口 ...