[洛谷]P2246 Hello World (升级版)
题目描述:
代码A:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dp[500005][11];
int main(int argc, char const *argv[])
{
string xx,s;
s=" helloworld";
cin>>xx;
int len=xx.size();
dp[0][0]=1;
for(int i=len;i;i--)
{
dp[i][0]=1;
xx[i]=xx[i-1];
if(xx[i]>='A' && xx[i]<='Z')
xx[i]=xx[i]-'A'+'a';
}
for(int i=1;i<=len;i++)
for(int j=1;j<=10;j++)
{
dp[i][j]=dp[i-1][j];
if(xx[i]==s[j])
dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
}
cout<<dp[len][10]<<endl;
return 0;
}
代码B:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dp[11];
int main(int argc, char const *argv[])
{
char ch,s[12]=" helloworld";
while(cin>>ch)
{
if(ch>='A' && ch<='Z')
ch=ch-'A'+'a';
if(ch=='h')
dp[1]++;
for(int i=10;i>=2;i--)
if(ch==s[i])
dp[i]=(dp[i]+dp[i-1])%mod;
}
cout<<dp[10]<<endl;
return 0;
}