思路:

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 ;
}

最新文章

  1. 使用python抓取婚恋网用户数据并用决策树生成自己择偶观
  2. 海洋女神建新installshield交流群了,原来的老群都满了,请加新群哦,记得认真填写验证信息
  3. MST:Agri-Net(POJ 1258)
  4. WPF MVVM初体验
  5. CMYK印刷色
  6. 可复用的js效果
  7. github注册使用以及体会
  8. 第一个Sprint冲刺第一天
  9. st_MES_InsertIntoSalaryManage
  10. 结构体dfield_t
  11. c# 学习笔记(二)
  12. Spark Kudu 结合
  13. 201621123050 《Java程序设计》第8周学习总结
  14. Entity Framework 查漏补缺 (三)
  15. EXT.net 图标靠右排列
  16. weblogic---- Remote远程调用
  17. webpack 中,importloaders 配置项的含义
  18. python 使用PyInstaller将程序打包
  19. sql 数据库日志收缩
  20. Java-控制台传递参数

热门文章

  1. wampserver64安装时出现计算机缺少MCVR110.DLL无法安装等
  2. Redis入门教程(二)— 基本数据类型
  3. 嵌入式开发之davinci--- 8168 电源调试总结
  4. 【STORAGE】Qlogic FC存储交换机cmd配置方法
  5. MongoDB数据库的初识
  6. hdu4908 &amp;amp; BestCoder Round #3 BestCoder Sequence(组合数学)
  7. atom及其插件activate-power-mode下载安装
  8. vsftp 777权限
  9. next数组求最小循环节
  10. BZOJ2843:极地旅行社(LCT入门题)