hdu5009Paint Pearls dp
来源:互联网 发布:数据库王珊第5版答案 编辑:程序博客网 时间:2024/06/07 06:08
#include<cstdio>#include<cstring>#include<iostream>#include<map>#include<algorithm>using namespace std ;const int maxn = 5e4+10 ;const int inf = 1e9 ;int dp[maxn] ;int a[maxn] ;map<int,int> ma;int pre[maxn] ;int last[maxn] ;int main(){ int n ; while(~scanf("%d" , &n)) { int len = 0 ; ma.clear() ; for(int i = 1;i <= n;i++){ scanf("%d" , &a[i]) ; if(ma[a[i]] == 0){ ma[a[i]] = ++len ; } } for(int i = 1;i <= n;i++){ a[i] = ma[a[i]] ; dp[i] = inf ; } dp[0] = 0 ; memset(pre , -1 , sizeof(pre)) ; memset(last , 0 , sizeof(last)) ; for(int i = n;i > 0;i--){ if(last[a[i]]) pre[last[a[i]]] = i ; last[a[i]] = i ; } dp[n] = n ;dp[0] = 0 ; for(int i = 0;i <= n;i++){ int cnt = 0 ; for(int j = i+1;j <= n;j++){ if(pre[j] <= i){ cnt++ ; } int tmp = cnt*cnt ; if(tmp + dp[i] > dp[n]) break ; dp[j] = min(dp[j] , dp[i]+tmp) ; } } printf("%d\n" , dp[n]) ; } return 0 ;}
0 1
- hdu5009Paint Pearls dp
- Pearls--DP
- POJ1260 Pearls DP
- POJ 1260 Pearls DP
- poj-1260-Pearls-dp
- hdu 1300 Pearls(dp)
- hdu 1300 Pearls DP
- ZOJ 1563 Pearls(DP)
- HDU 1300 Pearls(DP)
- poj 1260Pearls DP
- Pearls - POJ 1260 dp
- HDU 1300 Pearls(DP)
- hdu5009 Paint Pearls DP
- 【DP】HDU-1300 Pearls
- POJ 1260-Pearls(dp)
- Hdoj 1300 Pearls 【DP】
- HDU 1300 Pearls--dp
- poj 1260 Pearls dp
- RSA算法原理
- 归并排序(2-路)
- android开发技术博客
- PostgreSQL学习手册(客户端命令<二>)
- Hibernate的二级缓存
- hdu5009Paint Pearls dp
- mysql 横表和纵表转换
- sql替换NOT IN语句
- 秒杀多线程第六篇---经典线程同步 事件Event
- nyoj--914--Yougth的最大化(二分查找)
- webpy源码阅读
- codeforces-441B-Valera and Fruits【暴力】
- 关于平方和立方和,注意范围的取值顺序
- sicily 1125. Arnie versus the IRS