P2246 SAC#1 - Hello World(升级版)
典型的字符串dp
f[i][j]表示a串匹配到i,b串匹配到j的方案数。
if(a[i]==b[j])f[i][j]=f[i-1][j-1]+f[i-1][j];
if(a[i]!=b[j])f[i][j]=f[i-1][j];
显然可以用滚动数组优化空间
if(a[i]==b[j])f[j]+=f[j-1];
否则不用管。
什么?Why?
f[j-1]不是在f[j]之前更新了吗?
唉,不要惯性思维啊,倒着匹配不就完了,是不?

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<map>
#define mod 1000000007
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.23
using namespace std;
char a[],b[]="@helloworld";
long long cnt;
long long f[];
void in(long long &x)
{
long long y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=x*+c-'',c=g();
x*=y;
}
void o(long long x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main()
{
// freopen("t.in","r",stdin);
while(cin>>a[++cnt])
{
if(a[cnt]>='A'&&a[cnt]<='Z')a[cnt]+='a'-'A';
if(a[cnt]=='h')
{
f[]++;
f[]%=mod;
}
for(register long long j=;j>=;j--)
if(a[cnt]==b[j])f[j]=(f[j-]+f[j])%mod;
}
o(f[]%mod);
return ;
}

其实没必要开数组的。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
#define mod 1000000007
//by war
//2017.11.8
using namespace std;
int f[];
char a[]="@helloworld",x;
void in(int &x)
{
int y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=(x<<)+(x<<)+c-'',c=g();
x*=y;
}
void o(int x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main()
{
// freopen("t.in","r",stdin);
while(cin>>x)
{
if(x>='A'&&x<='Z')x=x-'A'+'a';
if(x=='h')
f[]++;
f[]%=mod;
for(register int i=;i>=;i--)
if(a[i]==x)
f[i]=(f[i]+f[i-])%mod;
}
o(f[]%mod);
return ;
}

P2246 SAC#1 - Hello World(升级版)的更多相关文章

  1. 洛谷P2246 SAC#1 - Hello World(升级版)

    题目背景 T1答案要mod1000000007(10^9+7),请重新提交,非常抱歉! 一天,智障的pipapi正在看某辣鸡讲义学程序设计. 题目描述 在讲义的某一面,他看见了一篇文章.这篇文章由英文 ...

  2. 洛谷11月月赛round.1

    太感动了#2 thwfhk 240 (801ms) 100 100 40   又一张明信片,话说10月的怎么还没收到   P2246 SAC#1 - Hello World(升级版) 题目背景 一天, ...

  3. Rdseed与SAC的安装

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  4. 4829 [DP]数字三角形升级版

    4829 [DP]数字三角形升级版  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 从数字三角形的顶部(如图, ...

  5. Linux 网络编程四(socket多线程升级版)

    //网络编程--客户端 #include <stdio.h> #include <stdlib.h> #include <string.h> #include &l ...

  6. MongoDB.WebIDE:升级版的Mongodb管理工具

    很早以前收藏了一片文章:<强大的MongoDB数据库管理工具>.最近刚好要做一些MongoDB方面的工作,于是翻出来温习了一下,用起来也确实挺方便.不过在使用过程中出现了一些个问题,加上更 ...

  7. 结对2.0--复利计算WEB升级版

    结对2.0--复利计算WEB升级版 复利计算再升级------------------------------------------------------------ 客户在大家的引导下,有了更多 ...

  8. C#枚举硬件设备(升级版)

    原文:C#枚举硬件设备(升级版) 先取设备类型: ; } }

  9. JBOSS集群技术升级版解决方案分享(图示篇)

    JBOSS集群技术升级版解决方案分享(实现篇)           前段时间,由于阿堂一直较忙,没有写点什么了,有空时一直在关注"web架构和性能,高并发,Cache层"技术领域的 ...

随机推荐

  1. 为什么还原innobackupex备份后查看到的Executed_Gtid_Set与xtrabackup_binlog_info不一致

    基本环境:官方社区版MySQL 5.7.19,innobackupex version 2.4.8 一.什么不一致 1.1.不一致 首先使用下面脚本来构建Executed_Gtid_Set与xtrab ...

  2. http raw post 之理解

    参考链接: https://imququ.com/post/four-ways-to-post-data-in-http.html http://blog.csdn.net/leyangjun/art ...

  3. ubuntu14.04 安装 openssh-server

    ubuntu自带的有openssh-client,所以可以通过 ssh username@host 来远程连接linux 可是要想通过ssh被连接,ubuntu系统需要有openssh-server, ...

  4. .Net Core中使用RabbitMQ

    (1).引入依赖 RabbitMQ.Client (2).编写发布者代码 var connectionFactory = new ConnectionFactory() { HostName=&quo ...

  5. 在手机的浏览器上通过连接打开App

    Android系统中实现 1.在系统系统自带的浏览器中 首先做成HTML的页面,页面内容格式如下: <a href="[scheme]://[host]/[path]?[query]& ...

  6. C++学习7-面向对象编程基础(多态性与虚函数、 IO文件流操作)

    多态 多态性是指对不同类的对象发出相同的消息将返回不同的行为,消息主要是指类的成员函数的调用,不同的行为是指不同的实现: 函数重载 函数重载是多态性的一种简单形式,它是指允许在相同的作用域内,相同的函 ...

  7. 【转】Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)

    [转]Python之xml文档及配置文件处理(ElementTree模块.ConfigParser模块) 本节内容 前言 XML处理模块 ConfigParser/configparser模块 总结 ...

  8. Majority Element(169) && Majority Element II(229)

    寻找多数元素这一问题主要运用了:Majority Vote Alogrithm(最大投票算法)1.Majority Element 1)description Given an array of si ...

  9. 经典]Linux内核中ioremap映射的透彻理解【转】

    转自:http://blog.csdn.net/lanyang123456/article/details/7403514 几乎每一种外设都是通过读写设备上的寄存器来进行的,通常包括控制寄存器.状态寄 ...

  10. ActiveMQ 入门Nodejs版

    ActiveMQ 入门下载与安装 官方下载地址 解压,运行bin/win[32|64]/activemq[.bat] 启动服务 环境信息 控制台: http://localhost:8161 默认端口 ...