区间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的更多相关文章

随机推荐

  1. servlet的多线程并发问题

    package gz.itcast.e_thread; import java.io.IOException; import javax.servlet.ServletException; impor ...

  2. python PIL相关操作

    项目中需要用python生成二维码,这里记录一下相关PIL相关操作. RGBA问题: 需要将图片A粘贴到图片B上,之前没有注意透明度问题,A的背景是透明的,粘贴到B上后,A的周围是黑的.后来才发现是P ...

  3. shell脚本网络流量实时查看

    Linux网络流量实时查看脚本,Centos默认没有自带流量查看工具,通过网上的资料做了一些修改 #!/bin/bash # Author: Ca0gu0 # Script Name: idev.sh ...

  4. Appium 使用android_uiautomator定位元素时报错: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

    使用 android_uiautomator 定位元素时(现在用的还不太熟,对于这个方法还需要加深了解)报错: 报错信息:The requested resource could not be fou ...

  5. 怎么设置font awesome图标的大小?

    <i class="fa fa-camera-retro fa-lg"></i> fa-lg <i class="fa fa-camera- ...

  6. C解析config

    #cat bb.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include < ...

  7. dp有哪些种类

    dp有哪些种类 一.总结 一句话总结: 二.dp动态规划分类详解 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. * ...

  8. 使用PHP操作MongoDB数据库

    1.连接MongoDB数据库(在已安装php-mongodb扩展的前提下) $config = "mongodb://{$user}:{$pass}@{$host}:{$port}" ...

  9. MySQL数据库操作(一)

    一.数据操作 1.显示数据库 show databases; 2.创建数据库 #utf- create database 数据库名称 default charset utf8 collate utf8 ...

  10. Spring MVC 单元测试Demo

    @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations={" ...