LA6878
区间dp
dp[i][j]存i->j区间的所有取值
然后枚举分割点,枚举两个存的值,分别运算存储。
看见这种不确定分割顺序,两个区间合并的情况,就要用区间dp。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, kase;
int vis[N * ];
char s[N];
vector<int> dp[N][N];
int main()
{
while(scanf("%s", s + ))
{
if(s[] == '') break;
n = strlen(s + );
for(int i = ; i <= n; ++i)
for(int j = i; j <= n; ++j)
dp[i][j].clear();
for(int i = ; i <= n; ++i)
{
if(s[i] == 'I') dp[i][i].push_back();
if(s[i] == 'V') dp[i][i].push_back();
if(s[i] == 'X') dp[i][i].push_back();
if(s[i] == 'L') dp[i][i].push_back();
if(s[i] == 'C') dp[i][i].push_back();
}
for(int len = ; len <= n; ++len)
for(int i = ; i <= n - len + ; ++i)
{
for(int j = i; j < i + len; ++j)
for(int x = ; x < dp[i][j].size(); ++x)
for(int y = ; y < dp[j + ][i + len - ].size(); ++y)
if(dp[i][j][x] < dp[j + ][i + len - ][y] && !vis[dp[j + ][i + len - ][y] - dp[i][j][x]])
{
dp[i][i + len - ].push_back(dp[j + ][i + len - ][y] - dp[i][j][x]);
vis[dp[j + ][i + len - ][y] - dp[i][j][x]] = ;
}
else if(dp[i][j][x] >= dp[j + ][i + len - ][y] && !vis[dp[j + ][i + len - ][y] + dp[i][j][x]])
{
vis[dp[j + ][i + len - ][y] + dp[i][j][x]] = ;
dp[i][i + len - ].push_back(dp[j + ][i + len - ][y] + dp[i][j][x]);
}
for(int x = ; x < dp[i][i + len - ].size(); ++x)
vis[dp[i][i + len - ][x]] = ;
}
sort(dp[][n].begin(), dp[][n].end());
printf("Case %d:", ++kase);
for(int i = ; i < dp[][n].size(); ++i)
printf(" %d", dp[][n][i]);
puts("");
}
return ;
}
LA6878的更多相关文章
随机推荐
- CSS——个人资料demo
1.上下外边距合并,选最大值. 2.两个input标签在编辑中如果换行了,在浏览器中显示的时候会自动增加一些距离. <!DOCTYPE html> <html lang=" ...
- (转)Struts2访问Servlet的API及......
http://blog.csdn.net/yerenyuan_pku/article/details/67315598 Struts2访问Servlet的API 前面已经对Struts2的流程已经执行 ...
- 网络爬虫 robots协议 robots.txt
网络爬虫 网络爬虫是一个自动提取网页的程序,它为搜索引擎从万维网上下载网页,是搜索引擎的重要组成.传统爬虫从一个或若干初始网页的URL开始,获得初始网页上的URL,在抓取网页的过程中,不断从当前页面上 ...
- Java切换JDK版本的方法及技巧
由于项目的不同安排,之前项目开发时,使用的jdk版本为1.8,现临时接手一以前项目,需要更换jdk版本. 安装 不再赘述,去Oracle网站(https://www.oracle.com/techne ...
- 【转载】Linux下各文件夹的含义和用途
原文地址:https://www.cnblogs.com/lanqingzhou/p/8037269.html Linux下各文件夹的含义和用途 Linux根目录”/“下各个系统文件夹的含义和用途 1 ...
- vue中使用Swiper
第一步:安装swiper在项目目录下打开命令窗口输入命令:npm install swiper 第二步:引入js文件 第三步:引入css文件在main.js文件中引入css文件
- 【LeetCode】2、Add Two Numbers
题目等级:Medium 题目描述: You are given two non-empty linked lists representing two non-negative integers. ...
- Lua练习题集嚢
--1.table.sort() am = {"cc","nn","ll","dd"} arr = function ( ...
- P2884 [USACO07MAR]每月的费用Monthly Expense
题目描述 Farmer John is an astounding accounting wizard and has realized he might run out of money to ru ...
- js调用ro的webservice
Enabling JavaScript Access on the Server Drop the JavaScriptHttpDispatcher component onto the server ...