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