思路:

dp。

实现:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f; string s;
int n, cnt = ;
int dp[][][];
int path[][][];
int ans[]; int trans(int index)
{
return s[index] - '';
} int dfs(int now, bool lz, int mod)
{
if (dp[now][lz][mod] != -)
return dp[now][lz][mod];
if (now == n)
{
if (lz && !mod)
return ;
return -INF;
}
int x, y = -INF;
x = dfs(now + , lz, mod);
path[now][lz][mod] = ;
if (s[now] != '' || (s[now] == '' && lz))
{
y = dfs(now + , true, (mod + trans(now)) % ) + ;
if (y > x)
{
path[now][lz][mod] = ;
return dp[now][lz][mod] = y;
}
}
return dp[now][lz][mod] = x;
} void get_path(int now, bool lz, int mod)
{
if (now == n)
return;
if (path[now][lz][mod])
{
ans[cnt++] = now;
get_path(now + , true, (mod + trans(now)) % );
}
else
{
get_path(now + , lz, mod);
}
} int main()
{
cin >> s;
n = s.length();
memset(dp, -, sizeof(dp));
int tmp = dfs(, false, );
if (tmp <= )
{
if (s.find("") != string::npos)
puts("");
else
puts("-1");
}
else
{
get_path(, false, );
for (int i = ; i < cnt; i++)
{
putchar(s[ans[i]]);
}
puts("");
}
return ;
}

CF792C Divide by Three的更多相关文章

  1. [LeetCode] Divide Two Integers 两数相除

    Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...

  2. Pairwise Sum and Divide 51nod

      1305 Pairwise Sum and Divide 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 有这样 ...

  3. Conquer and Divide经典例子之Strassen算法解决大型矩阵的相乘

    在通过汉诺塔问题理解递归的精髓中我讲解了怎么把一个复杂的问题一步步recursively划分了成简单显而易见的小问题.其实这个解决问题的思路就是算法中常用的divide and conquer, 这篇 ...

  4. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  5. [leetcode] 29. divide two integers

    这道题目一直不会做,因为要考虑的corner case 太多. 1. divisor equals 0. 2. dividend equals 0. 3. Is the result negative ...

  6. Leetcode Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 不用乘.除.求余操作,返回两整数相除的结果,结 ...

  7. uva10375 Choose and Divide(唯一分解定理)

    uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...

  8. 51nod1305 Pairwise Sum and Divide

    题目链接:51nod 1305 Pairwise Sum and Divide 看完题我想都没想就直接暴力做了,AC后突然就反应过来了... Floor( (a+b)/(a*b) )=Floor( ( ...

  9. leetcode-【中等题】Divide Two Integers

    题目 Divide two integers without using multiplication, division and mod operator. If it is overflow, r ...

随机推荐

  1. 如何离线分析Kafka海量业务消息?1分钟快速为您支招

    场景介绍 说起Kafka,许多使用者对它是又爱又恨.Kafka是一种分布式的.基于发布/订阅的消息系统,其极致体验让人欲罢不能,但操心的运维.复杂的安全策略.可靠性易用性的缺失等,仍需要使用者付出诸多 ...

  2. LruCache & DiskLruCache

    在用户界面(UI)加载一张图片时很简单,然而,如果你需要加载多张较大的图像,事情就会变得更加复杂,.在许多情况下(如与像的ListView GridView或ViewPager的组件),屏幕上的图片的 ...

  3. S2SH的集成(Struts2,Spring,Hibernate)----青软S2SH(笔记)

  4. cocos2d-x 打包成so文件之后,假设出现错误,能够使用ndk-stack来查看里面的异常

    cocos2d-x  打包成so文件之后,假设出现错误,能够使用ndk-stack来查看里面的异常 详细方法.自行百度.

  5. cocos2d-x-2.1.5版本在Xcode4.2中首次编译ccimage Semantic Issue出错解决方法

    // XXX: ios7 casting [str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) wi ...

  6. Velocity魔法堂系列一:入门示例(转)

    Velocity魔法堂系列一:入门示例 一.前言 Velocity作为历史悠久的模板引擎不单单可以替代JSP作为Java Web的服务端网页模板引擎,而且可以作为普通文本的模板引擎来增强服务端程序文本 ...

  7. thinkphp不能够将ueditor中的html文本显示

    因为这个问题花费了我好长时间,非常的急躁.fuck!! 这次我首先在富文本框中输入了一些文本,这些文本是带有样式的,比如是代码.然后存入数据库,但是当我再一次将它取出来打算放入富文本框中的时候,马丹, ...

  8. SpringBoot项目以服务器方式启动

    SpringBoot项目,如果未引入Web相关依赖,不会以服务器方式进行启动,会以应用的方式启动并结束 <dependency> <groupId>org.springfram ...

  9. IDE工具的[多行光标编辑模式]

    Sublime Text3:Ctrl+Alt+上下键 Eclipse:Shift+Alt+A,进入退出多光标模式 IDEA:Shift + ctrl + alt + 鼠标左键 收集链接 IDEA:ht ...

  10. node+ws模块实现websocket

    先来吐槽一下,想要找点技术文章真tm不容易,全是jb复制粘贴,还冒充原创.搜索一个ws实现websocket全是一样的.一个字都没变,我能说什么.最后想到搜索ws模块githup居然前两页没有,也是那 ...