题目链接:点击打开链接

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<set>
  5. #include<vector>
  6. #include<map>
  7. #include<math.h>
  8. #include<queue>
  9. #include<string>
  10. #include<stdlib.h>
  11. #include<algorithm>
  12. using namespace std;
  13. #define N 110
  14. #define ll int
  15.  
  16. ll n, a, b;
  17. ll h[N];
  18. vector<int>G,ans;
  19. void dfs(int u, bool hehe){//hehe=true表示u-1没死
  20. if(u==n && hehe==false){
  21. if(G.size()<ans.size())
  22. ans = G;
  23. return ;
  24. }
  25. int siz = 0;
  26. if(hehe) {
  27. while(h[u-1]>0)siz++,h[u-1]-=b, h[u]-=a, h[u+1]-=b, G.push_back(u);
  28. }
  29. if(h[u]>0) {
  30. while(h[u]>0) {
  31. dfs(u+1,true);
  32. h[u-1]-=b;
  33. h[u]-=a;
  34. h[u+1]-=b;
  35. siz++;
  36. G.push_back(u);
  37. }
  38. }
  39. dfs(u+1,false);
  40. h[u]+=a*siz;
  41. h[u+1]+=b*siz;
  42. h[u-1]+=b*siz;
  43. while(siz--)G.erase(G.end()-1);
  44. }
  45. int main(){
  46. ll i, j;
  47. while(~scanf("%d %d %d",&n,&a,&b)){
  48. G.clear(); ans.clear();
  49. for(i=1;i<=n;i++)scanf("%d",&h[i]), h[i]++;
  50. while(h[1]>0){
  51. h[2] -= a;
  52. h[1] -= b;
  53. h[3] -= b;
  54. ans.push_back(2);
  55. }
  56. while(h[n]>0){
  57. h[n-2] -= b;
  58. h[n-1] -= a;
  59. h[n] -= b;
  60. ans.push_back(n-1);
  61. }
  62. G = ans;
  63. for(i=1;i<=100;i++)ans.push_back(i);
  64. dfs(2,false);
  65. printf("%d\n",ans.size());
  66. for(i = 0; i < ans.size(); i++)printf("%d%c",ans[i],i==ans.size()-1?'\n':' ');
  67. }
  68. return 0;
  69. }
  70.  
  71. /**/

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

  1. 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 ...

  2. 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 ...

  3. codeforces 6D

    D. Lizards and Basements 2 time limit per test 2 seconds memory limit per test 64 megabytes input st ...

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

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

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

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  6. 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 ...

  7. hdu 1010 Tempter of the Bone(dfs暴力)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  8. NOIP 2002提高组 选数 dfs/暴力

    1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...

  9. 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 ...

随机推荐

  1. Spring boot基础:配置文件配置变量、多环境的配置

    一.配置 resources下面application.properties 1.普通配置 resources下面application.properties,比如写上:server.port=909 ...

  2. Android制作曲线、柱状图、饼形等图表——使用AChartEngine

    之前在java开发中实现图表使用JFreeChar组件,最近有个小项目要求在Android端进行数据分析,如何实现图表呢?查了一下google提供了一个开源组件Achartengine非常好用,可实现 ...

  3. 【翻译自mos文章】CRS显示 正在执行的db instance 是offline状态

    CRS显示 正在执行的db instance 是offline状态 转自: CRS shows Running Instance Status as OFFLINE (Doc ID 1673397.1 ...

  4. IOS网络访问详解

    第一.访问网络的方式 同步请求:数据的请求过程是由主线程发起的,网络加载需要一定的时间,因此会堵塞主线程 异步请求:数据的请求在多线程中完成 同步请求无法取消,异步请求的过程中可以取消,同步请求无法监 ...

  5. (转)Unity中protobuf的使用方法

    在移动手机游戏开发中,目前Unity3D已成为比较主流的开发技术. 那么对于客户端服务器协议的打解包,我们有3中常用的处理方式: 1.自定义结构体:在协议中直接传输代码中自定义的结构体:这种方式的坏处 ...

  6. C++中用完需要释放掉内存的几个类

      BSTR BSTR bstrXML = NULL; //用完以后,或者 catch段中 if(bstrXML) ::SysFreeString(result); VARIANT VARIANT v ...

  7. bash參考手冊之六(Bash特性)

    6 Bash 特性 这部分描写叙述Bash独有的特性. *  调用Bash : Bash能够接受的命令行选项. *  Bash启动文件 : Bash何时及怎样运行脚本. *  交互Shell : 什么 ...

  8. Bootstrap3实现的响应式幻灯滑动效果个人作品集/博客网站模板

    ​在线演示 本地下载 如果你想学习如何开发和使用的话,请参考我们免费的课程: Bootstrap3开发滑动风格的博客网站模板

  9. IN 查询时出现ORA-01795:列表中的最大表达式数为1000解决方法

    问题描写叙述: SQL进行IN查询时出现:java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000 解决的方法: 问题原因是:SQL进行IN查询时.IN中的 ...

  10. ubuntu 安装 codelite

    http://www.linuxidc.com/Linux/2013-06/85332.htm Ubuntu 12.04下为codelite增添更新源 1.获取codelite的公钥 sudo apt ...