思路:

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. 硬件开发之bt输出---BT656/BT601/BT1120协议以及DM365/DM355/DM6467上使用的YUV颜色空间说明

    http://blog.csdn.net/zhouzhuan2008/article/details/17168133

  2. 用javascript写一个前端等待控件

    前端等待控件有啥新奇的?什么jquery啦,第三方控件啦,好多好多,信手拈来. 因为项目使用了bootstrap的原因,不想轻易使用第三方,怕不兼容.自己写一个. 技术点包括动态加载CSS,javas ...

  3. IntelliJ IDEA jrebel6 安装,破解

    一.Setting中在线安装JRebel插件,install 二.拷贝下载的jrebel.rar解压后 把里面内容覆盖IDEA插件安装目录中此插件目录之下 下载:http://pan.baidu.co ...

  4. XMU 1613 刘备闯三国之三顾茅庐(一) 【并查集】

    1613: 刘备闯三国之三顾茅庐(一) Time Limit: 1000 MS  Memory Limit: 128 MBSubmit: 99  Solved: 29[Submit][Status][ ...

  5. mongo13----application set与分片结合

    replation set配合分片 打开3台服务器,B服务器()放configserv, C,D服务器(203.204)放置复制集 .203和192.168.1.204分别运行之前的sh start. ...

  6. debian webmin 安装

    /******************************************************************** * debian webmin 安装 * 说明: * 在服务 ...

  7. 进程、轻量级进程(LWP)、线程

    进程.轻量级进程(LWP).线程 进程:程序执行体,有生命期,用来分配资源的实体 线程:分配CPU的实体. 用户空间实现,一个线程阻塞,所有都阻塞. 内核实现,不会所用相关线程都阻塞.用LWP实现,用 ...

  8. 解决Linux主机上的 远程MySQL客户端无法连接的问题

    无法连接到 MySQL 数据库可能的原因有: 1. PHP 无法连接 MySQL 可能是 PHP 配置不正确,没加上连接 MySQL 的功能. 2. MySQL 软件包升级,但没有升级数据库,或安装 ...

  9. Linux 软链接 硬链接 ln命令(简约说明版)

    注意:路径使用绝对路径!! 解决方法: 当我们需要在不同的目录下用到同一个文件时,会用到以下命令. 命令:ln 作用:为某一个文件在另外一个位置建立一个同步的链接 语法:ln [option] 源文件 ...

  10. Integer和int的区别(转)

    public class TestInteger { public static void main(String[] args) { int i = 128; Integer i2 = 128; I ...