首页
Web开发
Windows程序
编程语言
数据库
移动开发
系统相关
微信
其他好文
会员
首页
>
其他好文
> 详细
hdu4455Substrings dp
时间:
2015-04-07 21:38:45
阅读:
134
评论:
0
收藏:
0
[点我收藏+]
标签:
// dp[i+1] = dp[i] + dis[i] - c[i] ;
// dp[i] 表示子串长度为i的不同数的和
//dis[i] 表示所有数在其前面和其相同的点的最短距离大于等于i的和
//c[i] 表示最后一个长度为i的子序列的不同数的和
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std ;
const int maxn = 1000010 ;
__int64 dp[maxn] ;
int a[maxn] ;
int dis[maxn] ;
int last[maxn] ;
int Hash[maxn] ;
int main()
{
// freopen("in.txt","r",stdin) ;
int N ;int Q ;
while(scanf("%d",&N) && N)
{
memset(Hash , 0 , sizeof(Hash));
memset(dis , 0 , sizeof(dis)) ;
for(int i = 1;i <= N;i++)
{
scanf("%d" , &a[i]);
if(Hash[a[i]])
dis[i - Hash[a[i]]]++;
else
dis[i] ++ ; //对于前面没有相同的数,假定和它相同的点的数为0
Hash[a[i]] = i;
}
memset(Hash , 0 ,sizeof(Hash));
for(int i = N; i > 0; i--)
{
dis[i] += dis[i+1] ;
last[i] = last[i+1] ;
if(!Hash[a[i]])
last[i]++ ;
Hash[a[i]] = 1;
}
dp[1] = N;
for(int i = 2; i <= N;i++)
dp[i] = dp[i-1] + (__int64)dis[i] - (__int64)last[N - i +2] ;
scanf("%d" ,&Q) ;
while(Q--)
{
int query ;
scanf("%d" ,&query);
printf("%I64d\n",dp[query]) ;
}
}
return 0;
}
hdu4455Substrings dp
标签:
原文地址:http://blog.csdn.net/cq_pf/article/details/44925825
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年07月29日 (22)
2021年07月28日 (40)
2021年07月27日 (32)
2021年07月26日 (79)
2021年07月23日 (29)
2021年07月22日 (30)
2021年07月21日 (42)
2021年07月20日 (16)
2021年07月19日 (90)
2021年07月16日 (35)
周排行
更多
分布式事务
2021-07-29
OpenStack云平台命令行登录账户
2021-07-29
getLastRowNum()与getLastCellNum()/getPhysicalNumberOfRows()与getPhysicalNumberOfCells()
2021-07-29
【K8s概念】CSI 卷克隆
2021-07-29
vue3.0使用ant-design-vue进行按需加载原来这么简单
2021-07-29
stack栈
2021-07-29
抽奖动画 - 大转盘抽奖
2021-07-29
PPT写作技巧
2021-07-29
003-核心技术-IO模型-NIO-基于NIO群聊示例
2021-07-29
Bootstrap组件2
2021-07-29
友情链接
兰亭集智
国之画
百度统计
站长统计
阿里云
chrome插件
新版天听网
关于我们
-
联系我们
-
留言反馈
© 2014
mamicode.com
版权所有 联系我们:gaon5@hotmail.com
迷上了代码!