当前位置:网站首页>Digital children < daily question> (Digital DP)
Digital children < daily question> (Digital DP)
2022-07-06 04:31:00 【CTGU-Yoghurt】
subject :
Topic link : Sign in — major IT Written interview preparation platform _ Cattle from https://ac.nowcoder.com/acm/contest/23480/D
Ideas :
digit dp The title of is usually a set of templates
Based on the original template
Change according to the subject conditions
So as to meet the requirements of the topic
The following three questions are analyzed
To meet the requirements of the topic 1 We have to be right
Sum every two adjacent digits
And judge whether it is a prime number
If not, proceed dfs
Because the title is required to be at least one digit 1
We don't know who is 1
So the judgment of this condition
You need to fill in this number completely before you can judge
If the digits have 1 And
No, 1 The situation of
General digits dp The topic will have some requirements
We can go through lead
Find the highest position
In this way, you can remove the leading 0 Influence
Code details :
#include<stdio.h>
#include<iostream>
using namespace std;
#include<string.h>
const int N = 15;
#define int long long// take int The defined variable is converted to long long
bool check(int n)// Check whether it is prime
{
return n == 2 || n == 3 || n == 5 || n == 7 || n == 11
|| n == 13 || n == 17 || n == 19;
}
int l, r, a[N], len, dp[N][N][2];// first [] What's the number , the second [] Indicates the number on this bit , Third [] Indicates whether it contains at least one 1
int dfs(int pos, int pre, int lead, int sum1, int limit)
{
if (pos == 0) return sum1;// Traverse all digits , Number of schemes returned ( contains 1 Then return to 1, Otherwise return to 0)
if (limit == 0 && lead==0 && dp[pos][pre][sum1] != -1)
return dp[pos][pre][sum1];// Not the highest position , There is no forerunner 0, And have been memorized ( Once traversed )
int up = limit ? a[pos] : 9;// Determine whether it is the highest
int ans = 0;
for (int i = 0; i <= up; i++)
{
if (lead == 0 && check(pre + i)==0) continue;// There is no forerunner 0, And the addition of adjacent positions is not a prime number
ans += dfs(pos - 1, i, lead && i == 0, (i == 1) || sum1, limit && i == up);
}
// The front is not the highest position , There is no forerunner 0
if ( limit == 0 && lead==0 )
dp[pos][pre][sum1] = ans;// Memorization results
return ans;
}
int quwei(int n)
{
len = 0;
while (n) a[++len] = n % 10,n/=10;
return dfs(len, 0,1,0,1);
}
signed main()// Pay attention to the int Transformed into long long So use signed main)()
{
cin >> l >> r;
memset(dp, -1, sizeof(dp));
cout << quwei(r) - quwei(l - 1)<<endl;
return 0;
}
PS: I don't understand digital dp You can see what bloggers upload PPT Oh .
边栏推荐
- HotSpot VM
- Overturn your cognition? The nature of get and post requests
- 脚本生命周期
- QML和QWidget混合开发(初探)
- VPP performance test
- JVM garbage collector concept
- 捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- Stable Huawei micro certification, stable Huawei cloud database service practice
- coreldraw2022新版本新功能介绍cdr2022
猜你喜欢
Query the number and size of records in each table in MySQL database
颠覆你的认知?get和post请求的本质
Execution order of scripts bound to game objects
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
Cross domain and jsonp details
Dry goods collection | Vulkan game engine video tutorial
Coreldraw2022 new version new function introduction cdr2022
图应用详解
View workflow
随机推荐
I'd like to ask about the current MySQL CDC design. In the full volume phase, if a chunk's binlog backfill phase,
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
动态规划(树形dp)
10個 Istio 流量管理 最常用的例子,你知道幾個?
绑定在游戏对象上的脚本的执行顺序
IDEA编译JSP页面生成的class文件路径
我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
Mysql数据库慢sql抓取与分析
Script lifecycle
[Zhao Yuqiang] deploy kubernetes cluster with binary package
E. Best Pair
Comprehensive ability evaluation system
. Net interprocess communication
Lombok原理和同时使⽤@Data和@Builder 的坑
The most detailed and comprehensive update content and all functions of guitar pro 8.0
P3500 [poi2010]tes intelligence test (two points & offline)
CertBot 更新证书失败解决
1008 circular right shift of array elements (20 points)