2010辽宁省赛F(字典树,动态规划)
using namespace std;
int n,x;
char s[10010];
char a[31010];
int val[100010];
int ch[100010][30];
int dp[100010];
int main()
{
while(~scanf("%d",&n))
{
scanf("%s",s+1);
int len=strlen(s+1);
memset(ch[0],0,sizeof(ch[0]));
int cnt=0;//记录编号
for(int i=1;i<=n;i++)
{
int u=0;//父节点,0为根节点
scanf("%s%d",a,&x);
for(int j=0;j<strlen(a);j++)
{
if(!ch[u][a[j]-'a'])//字典树中该位置已存在该字母
{
ch[u][a[j]-'a']=++cnt;
memset(ch[cnt],0,sizeof(ch[cnt]));
val[cnt]=0;
u=ch[u][a[j]-'a'];
}
val[u]=max(val[u],x);//u为结尾结点的编号,val[u]表示该串的权重
}
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=1;i<=len;i++)
{
int u=0;
if(!dp[i-1])
continue;
for(int j=i;j<=i+30&&j<=len;j++)
{
if(ch[u][s[j]-'a'])
{
u=ch[u][s[j]-'a'];
if(val[u])//如果有以u结尾的字符串,检验它的权重加上i结束的字符串的权重是否比原来更大
dp[j]=max(dp[j],dp[i-1]+val[u]);
}
else
break;
}
}
}
return 0;
}
2010辽宁省赛F(字典树,动态规划)的更多相关文章
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- NBUT 1218 You are my brother 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...
- 2019icpc南京网络赛 F 主席树
题意 给一个\(n\)的全排列数组\(a\),求一个递推数组每一项的值:\(ans[i]=ans[j]+1\),\(j\)为\(a[pos[i]-k]到a[pos[i]+k],(pos[i]为i在数组 ...
- NBUT 1224 Happiness Hotel 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The life of Little A is good, and, he managed to get enoug ...
- ZOJ 1985 Largest Rectangle in a Histogram(刷广告)2010辽宁省赛
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21204 ...
- NBUT 1222 English Game 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...
- NBUT 1225 NEW RDSP MODE I 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A has became fascinated with the game Dota recent ...
- NBUT 1220 SPY 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
随机推荐
- jQuery查找子元素与后代元素
1. 子元素: $().children('选择器') 如选择type为file的子元素 $(this).children("input[type=file]") 或者 $(& ...
- list dict set comprehension 列表推导式 (字典推导式,集合推导式)
从一个list生成新的list [ word.upper() for word in 'hellO worlD!' ] 简单的语法,如果不用list comprehension, 则要用更长的代码. ...
- Ffmpeg转码研究一
Ffmpeg是一款功能强大的视频处理工具,那么转码肯定不是问题的,因为项目的需求,对转码进行了研究.刚开始首先去看了ffmpeg源代码中的一个例子transcode.c,但是发现该例子更应该称之为re ...
- dbcc练习1
dbcc tranceon(2588,3604) dbcc ind() dbcc page()
- poj2420 A Star not a Tree? 模拟退火
题目大意: 给定n个点,求一个点,使其到这n个点的距离最小.(\(n \leq 100\)) 题解 模拟退火上 #include <cmath> #include <cstdio&g ...
- Fortify代码扫描解决方案
Fortify扫描漏洞解决方案: Log Forging漏洞: 1.数据从一个不可信赖的数据源进入应用程序. 在这种情况下,数据经由getParameter()到后台. 2. 数据写入到应用程序或系统 ...
- DSP/BIOS程序启动顺序
基于TI的DSP芯片的应用程序分为两种:一般应用程序:DSP/BIOS应用程序. 为简化编程,TI提供了一套C的编程接口,它以API和宏的形式封装了TI的所有硬件模块,这套接口统称DSP/BIOS.D ...
- HDU1698(线段树入门题)
Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descrip ...
- virtual judge(专题一 简单搜索 B)
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- 【转】Pro Android学习笔记(十一):了解Intent(中)
Intent的构成 Intent可以带有action,data(由URI表达),extra data(key/value map,键值对),指定的类名(成为component name).一个inte ...