题目链接

传送门

思路

\(dp[i][j][k]\)表示第\(i\)次操作放\(j\)后与另一堆的重量差为\(k\)是否存在。

代码实现如下

  1. #include <set>
  2. #include <map>
  3. #include <deque>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <bitset>
  9. #include <cstdio>
  10. #include <string>
  11. #include <vector>
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <iostream>
  15. #include <algorithm>
  16. using namespace std;
  17. typedef long long LL;
  18. typedef pair<LL, LL> pLL;
  19. typedef pair<LL, int> pLi;
  20. typedef pair<int, LL> piL;;
  21. typedef pair<int, int> pii;
  22. typedef unsigned long long uLL;
  23. #define lson rt<<1
  24. #define rson rt<<1|1
  25. #define lowbit(x) x&(-x)
  26. #define name2str(name) (#name)
  27. #define bug printf("*********\n")
  28. #define debug(x) cout<<#x"=["<<x<<"]" <<endl
  29. #define FIN freopen("in","r",stdin)
  30. #define IO ios::sync_with_stdio(false),cin.tie(0)
  31. const double eps = 1e-8;
  32. const int mod = 1e9 + 7;
  33. const int maxn = 1e5 + 7;
  34. const double pi = acos(-1);
  35. const int inf = 0x3f3f3f3f;
  36. const LL INF = 0x3f3f3f3f3f3f3f3fLL;
  37. int m, vis[15];
  38. bool dp[1007][15][105];
  39. char s[15];
  40. vector<int> vec;
  41. int main() {
  42. scanf("%s%d", s, &m);
  43. for(int i = 0; i < 10; ++i) {
  44. if(s[i] == '1') vis[i+1] = 1;
  45. }
  46. for(int i = 1; i <= 10; ++i) {
  47. if(vis[i]) dp[1][i][i] = 1;
  48. }
  49. for(int i = 2; i <= m; ++i) {
  50. for(int j = 1; j <= 10; ++j) {
  51. if(!vis[j]) continue;
  52. for(int k = 1; k <= 10; ++k) {
  53. if(!vis[k] || j == k) continue;
  54. for(int t = 1; t <= k; ++t) {
  55. if(!dp[i-1][k][t]) continue;
  56. if(j >= t) dp[i][j][j-t] = 1;
  57. }
  58. }
  59. }
  60. }
  61. int flag = 0;
  62. for(int i = 1; i <= 10; ++i) {
  63. for(int j = 1; j <= 10; ++j) {
  64. if(dp[m][i][j]) {
  65. flag = 1;
  66. break;
  67. }
  68. }
  69. if(flag) break;
  70. }
  71. if(!flag) puts("NO");
  72. else {
  73. puts("YES");
  74. int num1 = 0, num2 = 0;
  75. for(int i = 1; i <= 10; ++i) {
  76. for(int j = 1; j <= 10; ++j) {
  77. if(dp[m][i][j]) {
  78. num1 = i, num2 = j;
  79. break;
  80. }
  81. }
  82. if(num1) break;
  83. }
  84. vec.push_back(num1);
  85. for(int i = m - 1; i >= 1; --i) {
  86. for(int j = 1; j <= 10; ++j) {
  87. if(dp[i][j][num1-num2] && j != num1) {
  88. vec.push_back(j);
  89. num2 = num1 - num2;
  90. num1 = j;
  91. break;
  92. }
  93. }
  94. }
  95. for(int i = (int)vec.size() - 1; i >= 0; --i) {
  96. printf("%d%c", vec[i], i == 0 ? '\n' : ' ');
  97. }
  98. }
  99. return 0;
  100. }

Xenia and Weights(Codeforces Round #197 (Div. 2)+DP)的更多相关文章

  1. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  2. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)

    A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...

  3. Codeforces Round #197 (Div. 2)

    A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...

  4. Codeforces Round #197 (Div. 2) C,D两题

    开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...

  5. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Round #197 (Div. 2) : E

    看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...

  7. [置顶] Codeforces Round #197 (Div. 2)(完全)

    http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...

  8. Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】

    A. Helpful Maths time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #197 (Div. 2) : C

    哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...

随机推荐

  1. 使用tuna源安装docker-ce

    原文链接:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/ sudo add-apt-repository \ "deb [arch= ...

  2. commitlint那些事儿

    这里主要介绍提交信息用到的 cz 工具集. 一.生成器 commitizen,cz`生成提交说明`,格式化 git commit message. # 全局安装cz npm install -g co ...

  3. ThinkPHP3(命名空间、RBAC)

    命名空间 当开发大型项目的时候,可以会需要成千上万的文件 面向对象通过命名空间来解决这个问题的. PHP命名空间是PHP5.3以后才出现的. 命名空间中可以出现:类,函数,常量 只有const定义的常 ...

  4. cisco ap客户端无规律掉线

    设备 cisco air-ct2504-50-k9 cisco air-ap1832I-H-k9 首先根据这个帖子 https://community.cisco.com/t5/other-wirel ...

  5. Data-Structure-Notes

    Data Structure Notes Chapter-1 Sorting Algorithm Selection Sorting: /* * Selection Sort */ template& ...

  6. Python之路【第十一篇】:Python面向对象之封装

    一 引子 从封装本身的意思去理解,封装就好像是拿来一个麻袋,把青菜,土豆,花菜,还有苹果一起装进麻袋,然后把麻袋封上口子.照这种逻辑看,封装=‘隐藏’,这种理解是相当片面的. 在面向对象中这个麻袋就是 ...

  7. RT1052 BootLoader总结

    RT1052 BootLoader总结‍ 概述 Bootloader涉及到的RT1052单片机资源有:Cache,ram,外部SDRAM,ARM7汇编指令,外部dataFlash. 升级功能涉及到的其 ...

  8. 全栈项目|小书架|服务器端-NodeJS+Koa2 实现书籍详情接口

    通过上篇文章 全栈项目|小书架|微信小程序-首页水平轮播实现 我们实现了前端(小程序)效果图的展示,这篇文章来介绍服务器端的实现. 书籍详情分析 书籍详情页面如下: 从上图可以分析出详情页面大概有以下 ...

  9. 关于java中是引用传递还是值传递的问题

    关于JAVA中参数传递问题有两种,一种是按值传递(如果是基本类型),另一种是按引用传递(如果是對象).首先以两个例子开始:1)public class Test2 { public static vo ...

  10. 对于解决VS2015启动界面卡在白屏的处理方法

    有时候会遇到这种情况,仅供参考 找到devenv.exe所在文件夹,按住Shift,在空白地方右键,选择“在此处打开命令窗口”,在打开的窗口中输入devenv /ResetSettings 重新设置V ...