进食后人之如果你是从P6754过来的
查看原帖
进食后人之如果你是从P6754过来的
1510234
Z_L_H楼主2025/1/18 15:40

有几个易错点供参考

  • 要开string记录
  • 要把非回文串做成回文串(这个应该没人错吧)

AC node:

提示一下,本蒟蒻是直接用高精度死磕的,如思路不同请绕道而行(满级歪解)

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
string l,r;
int w[2005],dp[2005][15][15][2][2];
int dfs(int step,int last1,int last2,bool lim,bool zero)
{
	if(step == 0)return 1;
	if(dp[step][last1 + 1][last2 + 1][lim][zero] > -1)return dp[step][last1 + 1][last2 + 1][lim][zero];
	int up = 9;
	if(lim)up = w[step];
	int ans = 0;
	for(int i = 0;i <= up;i ++)
	{
		if(i != last1 && i != last2)
		{
			ans = (ans + dfs(step - 1,(!zero || i) ? i : -1,last1,lim && i == up,zero && i == 0)) % mod;
		}
	}
	return dp[step][last1 + 1][last2 + 1][lim][zero] = ans % mod;
}
int sol(string x)
{
	if(x == "-1")return 0;
	memset(dp,-1,sizeof(dp));
	int tot = 0;
	for(int i = x.size() - 1;i >= 0;i --)
	{
		w[++ tot] = x[i] - 48;
	}
	return dfs(tot,-1,-1,1,1);
}
string sub(string x,string y)
{
	if(x == y)return "0";
	int a[10001] = {},b[10001] = {},c[10001] = {};
	int k = 0;
	for(int i = x.length() - 1;i >= 0;i --)
	{
		k ++;
		a[k] = x[i] - '0';
	}
	k = 0;
	for(int i = y.length() - 1;i >= 0;i --)
	{
		k ++;
		b[k] = y[i] - '0';
	}
	int len = max(x.length(),y.length());
	for(int i = 1;i <= len;i ++)
	{
		c[i] = a[i] - b[i] + c[i];
		if(c[i] < 0)
		{
			c[i] += 10;
			c[i + 1] -= 1;
		}
	}
	while(c[len] == 0)len --;
	string z = "";
	for(int i = len;i >= 1;i --)
	{
		z = z + char(c[i] + '0');
	}
	return z;
}
int stringzin(string s)
{
	int num = 0;
	for(int i = 0;i < s.size();i ++)num = num * 10 + s[i] - '0';
	return num;
}
int Mod(string a,int b)
{
	int d = 0;
	for(int i = 0;i < a.size();i ++)
	{
		d = (d * 10 + (a[i] - '0')) % b;
	}
	return d;
}
signed main()
{
	cin>>l>>r;
	int k = 1,p = l.size();
	while(l[p - k] == '0' && p > k)l[p - k] = '9',k ++;
    l[p - k] -= 1;
	cout<<(((Mod(sub(r,l),mod)) - ((sol(r) - sol(l)) %mod + mod) % mod) % mod + mod) % mod;	
	return 0;
}
2025/1/18 15:40
加载中...