当前位置:网站首页>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 .
边栏推荐
- [Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
- Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
- Explain in simple terms node template parsing error escape is not a function
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- Is the mode of education together - on campus + off campus reliable
- E. Best Pair
- 【Try to Hack】john哈希破解工具
- R note prophet
- Basic use of MySQL (it is recommended to read and recite the content)
- CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
猜你喜欢

捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统

MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0

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

10 exemples les plus courants de gestion du trafic istio, que savez - vous?

Mysql数据库慢sql抓取与分析

MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】

Query the number and size of records in each table in MySQL database

Recommendation system (IX) PNN model (product based neural networks)

Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)

Path of class file generated by idea compiling JSP page
随机推荐
C. The third problem
牛顿插值法
11. Intranet penetration and automatic refresh
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
【HBZ分享】ArrayList的增删慢查询快的原因
JVM garbage collector concept
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
Solve the compilation problem of "c2001: line breaks in constants"
Stable Huawei micro certification, stable Huawei cloud database service practice
Meet diverse needs: jetmade creates three one-stop development packages to help efficient development
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
2328. Number of incremental paths in the grid graph (memory search)
SharedPreferences 源码分析
Yyds dry goods inventory OSI & tcp/ip
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
Practical development of member management applet 06 introduction to life cycle function and user-defined method
How many of the 10 most common examples of istio traffic management do you know?
电脑钉钉怎么调整声音
2327. Number of people who know secrets (recursive)
