博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4960 记忆化搜索 DP
阅读量:6261 次
发布时间:2019-06-22

本文共 2622 字,大约阅读时间需要 8 分钟。

Another OCD Patient

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 490    Accepted Submission(s): 180

Problem Description
   Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xiaoji is an OCD patient, he can't stand with the disorder of the volume of the N pieces of plasticene. Now he wants to merge some successive pieces so that the volume in line is symmetrical! For example, (10, 20, 20, 10), (4,1,4) and (2) are symmetrical but (3,1,2), (3, 1, 1) and (1, 2, 1, 2) are not.
   However, because Xiaoji's OCD is more and more serious, now he has a strange opinion that merging i successive pieces into one will cost ai. And he wants to achieve his goal with minimum cost. Can you help him?
   By the way, if one piece is merged by Xiaoji, he would not use it to merge again. Don't ask why. You should know Xiaoji has an OCD.
 
Input
   The input contains multiple test cases.
   The first line of each case is an integer N (0 < N <= 5000), indicating the number of pieces in a line. The second line contains N integers Vi, volume of each piece (0 < Vi <=10^9). The third line contains N integers ai
(0 < ai <=10000), and a1 is always 0.
   The input is terminated by N = 0.
 
Output
   Output one line containing the minimum cost of all operations Xiaoji needs.
 
Sample Input
5 6 2 8 7 1 0 5 2 10 20 0
 
Sample Output
10
Hint
In the sample, there is two ways to achieve Xiaoji's goal. [6 2 8 7 1] -> [8 8 7 1] -> [8 8 8] will cost 5 + 5 = 10. [6 2 8 7 1] -> [24] will cost 20.
 
Author
SYSU
 
Source
 
Recommend
We have carefully selected several similar problems for you:            
 
记忆化搜索,由于每个碎片值都是正数,所以每个前缀和后缀都是递增的,就可以利用twopointer去找到每个相等的位置,然后下一个区间相当于一个子问题,用记忆化搜索即可,复杂度接近O(n^2)
 
转自 :

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 10 #define N 500511 #define M 1512 #define mod 613 #define mod2 10000000014 #define ll long long15 #define maxi(a,b) (a)>(b)? (a) : (b)16 #define mini(a,b) (a)<(b)? (a) : (b)17 18 using namespace std;19 20 int n;21 ll v[N],sum[N];22 int a[N],dp[N][N];23 24 int DP(int l,int r)25 {26 //int i;27 //ll s1,s2;28 if(dp[l][r]!=-1) return dp[l][r];29 dp[l][r]=a[r-l+1];30 if(l>=r) return dp[l][r]=0;31 32 //i=l;33 int now=l;34 ll re;35 for(int i=r;i>=l;i--){36 re=sum[r]-sum[i-1];37 while(sum[now]-sum[l-1]

 

转载于:https://www.cnblogs.com/njczy2010/p/3924538.html

你可能感兴趣的文章
(转)Unity中protobuf的使用方法
查看>>
**PHP转义Json里的特殊字符的函数
查看>>
数据扩展性探讨和总结--转
查看>>
C# 导出资源文件到硬盘
查看>>
更改MySQL数据库的编码为utf8mb4
查看>>
TeamCity : .NET Core 插件
查看>>
由数量众多照片拼贴而成的马赛克图片
查看>>
andoid电阻触摸移植
查看>>
BootStrap 专题
查看>>
文件上传限制文件类型
查看>>
Netty线程模型
查看>>
判断一个变量是否为空的方法
查看>>
使用PS保存PDF为图片(JPG)
查看>>
Es对于日期处理
查看>>
使用RSA加密在Python中逆向shell
查看>>
关于和技术人员交流的一二三
查看>>
产生sdp文件供DSS使用
查看>>
怎样把数据汇到Excel中的心得经验
查看>>
spring+mybatis的多源数据库配置实战
查看>>
Oracle 导入外部文件数据库
查看>>