1001 Arithmetic of Bomb
Problem Description
简单的模拟题
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<iomanip>
//#define mem(dp,a) memset(dp,a,sizeof(dp))
//#define fo(i,n) for(int i=0;i<(n);i++)
//#define INF 0x3f3f3f3f
#define fread() freopen("data.txt","r",stdin)
#define fwrite() freopen("out.out","w",stdout)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int dir[4][2] = { {1,0} , {-1,0} , {0,-1}, {0,1} };
string s;
string re;
string st,tn;
int T;
int main()
{
ios_base::sync_with_stdio(false);
// fread();
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
// while(cin >> n)
cin >> T;
while(T--)
{
re.clear();
cin >> s;
int ind= 0;
for(;ind<s.size();ind++)
{
if(s[ind]=='(')
{
st.clear();
ind++;
while(s[ind]!=')')
{
st+=s[ind];
ind++;
}
// cout << st<<endl;
ind+=3;
tn.clear();
while(s[ind]!=')')
{
tn+=s[ind];
ind++;
}
ll num = atoll(tn.c_str());
for(ll i =0;i<num;i++)
{
re += st;
}
}
else
{
re+=s[ind];
}
}
ll ans = 0;
for(int i=0;i<re.size();i++)
{
ans = (ans%MOD * 10)%MOD;
ans += re[i]-'0';
ans %=MOD;
}
cout << ans<<endl;
}
return 0;
}
1003 Pokémon GO
DP
原题:http://blog.csdn.net/u010126535/article/details/20651999
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<iomanip>
//#define mem(dp,a) memset(dp,a,sizeof(dp))
//#define fo(i,n) for(int i=0;i<(n);i++)
//#define INF 0x3f3f3f3f
#define fread() freopen("data.txt","r",stdin)
#define fwrite() freopen("out.out","w",stdout)
using namespace std;
typedef long long ll;
const ll N = 10005;
const ll MOD = 1000000007;
ll a[N]={0};
ll b[N]={0};
ll re[N];
int T,n;
int main()
{
ios_base::sync_with_stdio(false);
// fread();
re[1] = 2;
b[1]=1;
for (int i=2;i<=N;i++)
b[i]=(b[i-1]*2%MOD);
a[1]=1;a[2]=6;
for (int i=3;i<=N;i++)
a[i]=(2*a[i-1]+b[i]+4*a[i-2])%MOD;
for(int k=2;k<=N;k++)
{
re[k]=4*a[k];
for(int i=2;i<k;i++)
{
re[k]+=((8*b[k-i]*a[i-1])%MOD+(8*a[k-i]*b[i-1])%MOD)%MOD;
re[k] %= MOD;
}
}
cin >> T;
while(T--)
{
cin >> n;
cout<<re[n]<<endl;
}
return 0;
}
1005 Valley Numer
数位DP
dp[位数][当前值][是否达到当前最大位][是否存在前置0]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100 + 5;
char str[N];
ll dp[N][11][2][2];
int len;
ll DFS(int pos, int pre, int up, int limit,int t) {
if (pos == len) {
return 1;
}
ll &now = dp[pos][pre][up][t];
if (!limit && now != -1) {
return now;
}
ll ret = 0;
int d = limit ? str[pos] - '0' : 9;
for (int i=0; i<=d; ++i) {
if (up)
{
if (i >= pre)
{
ret += DFS (pos + 1, i, 1&&!t, limit && i == d,i==0&&t);
ret%=MOD;
}
}
else
{
if (i <= pre)
{
ret += DFS (pos + 1, i, 0, limit && i == d,i==0&&t);
ret%=MOD;
}
else
{
ret += DFS (pos + 1, i, 1&&!t, limit && i == d,i==0&&t);
ret%=MOD;
}
}
}
if (!limit) {
now = ret;
}
return ret;
}
int main() {
// freopen("data.txt","r",stdin);
int T; scanf ("%d", &T);
while (T--) {
scanf ("%s", str);
len = strlen (str);
memset (dp, -1, sizeof (dp));
ll ans = (DFS (0, 0, 1, 1,1) - 1 +MOD)%MOD;
printf ("%I64d\n",ans);
}
return 0;
}