转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Xenia and Weights

Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes on the left scalepan, the fourth one goes on the right scalepan and so on. Xenia wants to put the total of m weights on the scalepans.

Simply putting weights on the scales is not interesting, so Xenia has set some rules. First, she does not put on the scales two consecutive weights of the same weight. That is, the weight that goes i-th should be different from the (i + 1)-th weight for any i (1 ≤ i < m). Second, every time Xenia puts a weight on some scalepan, she wants this scalepan to outweigh the other one. That is, the sum of the weights on the corresponding scalepan must be strictly greater than the sum on the other pan.

You are given all types of weights available for Xenia. You can assume that the girl has an infinite number of weights of each specified type. Your task is to help Xenia lay m weights on ​​the scales or to say that it can't be done.

Input

The first line contains a string consisting of exactly ten zeroes and ones: the i-th (i ≥ 1) character in the line equals "1" if Xenia has i kilo weights, otherwise the character equals "0". The second line contains integer m (1 ≤ m ≤ 1000).

Output

In the first line print "YES", if there is a way to put m weights on the scales by all rules. Otherwise, print in the first line "NO". If you can putm weights on the scales, then print in the next line m integers — the weights' weights in the order you put them on the scales.

If there are multiple solutions, you can print any of them.

Sample test(s)
input
  1. 0000000101
    3
output
  1. YES
    8 10 8
input
  1. 1000000000
    2
output
  1. NO

div2的C题,果断选择暴搜,搜到不符合的就往回跳,搜到正解就结束。。。

dp的话用dp[i][j][k]表示取到第i个的时候前一个重的一头比轻的重j且取的为k是否满足

  1. //#####################
  2. //Author:fraud
  3. //Blog: http://www.cnblogs.com/fraud/
  4. //#####################
  5. #include <iostream>
  6. #include <sstream>
  7. #include <ios>
  8. #include <iomanip>
  9. #include <functional>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <string>
  13. #include <list>
  14. #include <queue>
  15. #include <deque>
  16. #include <stack>
  17. #include <set>
  18. #include <map>
  19. #include <cstdio>
  20. #include <cstdlib>
  21. #include <cmath>
  22. #include <cstring>
  23. #include <climits>
  24. #include <cctype>
  25. using namespace std;
  26. #define XINF INT_MAX
  27. #define INF 0x3FFFFFFF
  28. #define MP(X,Y) make_pair(X,Y)
  29. #define PB(X) push_back(X)
  30. #define REP(X,N) for(int X=0;X<N;X++)
  31. #define REP2(X,L,R) for(int X=L;X<=R;X++)
  32. #define DEP(X,R,L) for(int X=R;X>=L;X--)
  33. #define CLR(A,X) memset(A,X,sizeof(A))
  34. #define IT iterator
  35. typedef long long ll;
  36. typedef pair<int,int> PII;
  37. typedef vector<PII> VII;
  38. typedef vector<int> VI;
  39. string str;
  40. int a[];
  41. int b[];
  42. bool flag=;
  43. int n;
  44. int tot;
  45. int dfs(int d,int lx,int rx){
  46. if(d==n){
  47. flag=;
  48. return ;
  49. }
  50. int x;
  51. x=upper_bound(a,a+tot,lx-rx)-a;
  52. for(int i=x;i<tot;i++){
  53. if(a[i]==b[d-])continue;
  54. b[d]=a[i];
  55. if(dfs(d+,rx+a[i],lx)){
  56. return ;
  57. }
  58. }
  59. return ;
  60. }
  61.  
  62. int main()
  63. {
  64. ios::sync_with_stdio(false);
  65. cin>>str;
  66. cin>>n;
  67. tot=;
  68. fill(a,a+,INF);
  69. for(int i=;i<str.length();i++)
  70. if(str[i]=='')a[tot++]=i+;
  71. ll lx=,rx=;
  72. int ans=;
  73. int last=;
  74. int i;
  75. int x=;
  76. for(int i=;i<tot;i++){
  77. b[]=a[i];
  78. if(dfs(,a[i],))break;
  79. }
  80. if(flag){
  81. cout<<"YES"<<endl;
  82. for(int i=;i<n;i++){
  83. if(i)cout<<" ";
  84. cout<<b[i];
  85. }
  86. cout<<endl;
  87. }
  88. else cout<<"NO"<<endl;
  89.  
  90. return ;
  91. }

代码君

codeforces 339C Xenia and Weights(dp或暴搜)的更多相关文章

  1. CodeForces 339C Xenia and Weights(暴力求解DFS)

    题意:给定 1-10的某几种砝码,给定的每种有无穷多个,然后放 m 个在天平上,要满足,相邻的两次放的砝码不能是同一种,然后是在天平两端轮流放,并且放在哪一个托盘上,那么天平必须是往哪边偏. 析:这个 ...

  2. codeforces 339C Xenia and Bit Operations(线段树水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginn ...

  3. codevs 1085 数字游戏 dp或者暴搜

    1085 数字游戏 2003年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单 ...

  4. [codeforces 339]C. Xenia and Weights

    [codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...

  5. Codeforces 1519F - Chests and Keys(暴搜+以网络流为状态的 dp)

    Codeforces 题目传送门 & 洛谷题目传送门 难度终于出来了--又独立切掉一道 *3200,凯信(所以我已经独立切掉三道 *3200 了?) 首先考虑我们已经知道了每个宝箱上有哪些锁, ...

  6. Xenia and Weights(深度优先搜索)

    Xenia and Weights time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. suoi62 网友跳 (暴搜+dp)

    传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...

  8. 子矩阵(暴搜(全排列)+DP)

    子矩阵(暴搜(全排列)+DP) 一.题目 子矩阵 时间限制: 1 Sec  内存限制: 128 MB 提交: 1  解决: 1 [提交][状态][讨论版] 题目描述 给出如下定义: 1. 子矩阵:从一 ...

  9. CodeForces - 357D - Xenia and Hamming

    先上题目: D. Xenia and Hamming time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. coconHashMap实现原理分析

    1. HashMap的数据结构 数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端. 数组 数组存储区间是连续的,占用内存严重,故空间复杂的很大.但数组的二分查找时间复杂度小,为O(1 ...

  2. nodeclub 学习记录

    源码地址:https://github.com/cnodejs/nodeclub 按照 它的步骤 在系统中跑没有出错,但是注册后没有发送邮件验证码,我将 controller层下面的sign.js 的 ...

  3. nginx日志管理与限速

    1.日志简介nginx日志主要有两种:访问日志和错误日志.访问日志主要记录客户端访问nginx的每一个请求,格式可以自定义:错误日志主要记录客户端访问nginx出错时的日志,格式不支持自定义.两种日志 ...

  4. NOR flash和NAND flash区别,RAM 和ROM区别d

    ROM和RAM指的都是半导体存储器,ROM是Read Only Memory的缩写,RAM是Random Access Memory的缩写.ROM在系统停止供电的时候仍然可以保持数据,而RAM通常都是 ...

  5. log4j日志分模块打印,同时不打印到控制台上

    由于定时刷新程序的启用,导致catalina.out配置文件中打入大量日志,致使程序调试困难.          无法正常查看日志.所以客户要求将性能流量配置日志迁移出catalina.out目录.修 ...

  6. HDU 1074 Doing Homework (状态压缩 DP)

    题目大意: 有 n 项作业需要完成,每项作业有上交的期限和需完成的天数,若某项作业晚交一天则扣一分.输入每项作业时包括三部分,作业名称,上交期限,完成所需要的天数.求出完成所有作业时所扣掉的分数最少, ...

  7. 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅲ

    2.4.3 堆的定义 数据结构二叉堆能够很好地实现优先队列的基本操作.在二叉堆的数组中,每个元素都要保证大于等于另两个特定位置的元素.相应地,这些位置的元素又至少要大于等于数组中的两个元素,以此类推. ...

  8. Linux usb子系统(一):子系统架构

    一.USB协议基础知识   前序:USB概念概述 USB1.0版本速度1.5Mbps(低速USB) USB1.1版本速度12Mbps(全速USB)  USB2.0版本速度480Mbps(高速USB). ...

  9. poj 2385 Apple Catching(dp)

    Description It and ) in his field, each full of apples. Bessie cannot reach the apples when they are ...

  10. php5.3 appache phpstudy win7win8win10下 运行速度慢

    php5.3 appache phpstudy win7win8win10下 运行速度慢 最近在部署服务器以及本地测试的时候发现了一个奇怪的现象,运行PHP程序的时候非常慢,起先以为是网速的原因,后经 ...