动态规划
1.确定dp数组的含义,本题dp[0]表示“2”的数量,dp[1]表示“20”的数量,dp[2]表示“202”的数量,dp[3]表示“2023”的数量。
2.确定递推公式,本题dp[1]=dp[1]+dp[0];
3.初始化dp数组,都为0
4.确定遍历方式:从前往后扫描每一个字符
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
string s;
int dp[4]={0};
for(int i=1;i<=2023;i++)
{
s+=to_string(i);
}
for(int i=0;i<s.size();i++)
{
if(s[i]=='2')
{
dp[0]++;
dp[2]+=dp[1];
}
if(s[i]=='0')
{
dp[1]+=dp[0];
}
if(s[i]=='3')
{
dp[3]+=dp[2];
}
}
cout <<dp[3];
return 0;
}
结果为5484660609。