当前位置:网站首页>Nine hours, nine people, nine doors problem solving Report
Nine hours, nine people, nine doors problem solving Report
2022-07-05 15:25:00 【wch(】
Nine hours, nine people, nine doors problem solving report
label : Dynamic programming , Number root
source : Cattle from 
Their thinking :
Tree radical
The first is to solve the digital root , We can set our own function to simulate and calculate , You can also use a faster formula .
Digital roots have such properties :x+9 And x Several of them are the same , That is, one number plus 9 After that, the number of its roots remains unchanged . So count a The root of the tree is a Yes 9 The result after taking the mold .
Formula for finding number root :a The number of roots b = (a-1) % 9+1
Proof of the nature of tree roots :
(abcd)% 9 = (a * 1000+b * 100+c * 10+d) % 9
= a%9+b%9+c%9+d%9
=(a+b+c+d)%9
Dynamic programming ( knapsack )
First think about how the state shifts , Set the following array dp[i-1][j], Before presentation i People can open the first j The maximum number of combinations of doors , At this point, we consider adding another person , Just call me this person , How will the maximum number of combinations of each door change after joining me , We can divide the maximum number of combinations into three parts :
There is no one else : dp[i][a[i]]=1;
There are others without me :dp[i][j]=(dp[i][j]+dp[i-1][j])%M;
I have others :dp[i][(j+a[i]-1)%9+1]=(dp[i][(j+a[i]-1)%9+1]+dp[i-1][j])%M
Code implementation :
#include <iostream>
#include <stdio.h>
using namespace std;
int a[100500];
int dp[100500][10];
const int M=998244353;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]=(a[i]-1)%9+1;
}
for(int i=1;i<=n;i++){
dp[i][a[i]]=1;
for(int j=1;j<=9;j++){
dp[i][j]=(dp[i][j]+dp[i-1][j])%M;
dp[i][(j+a[i]-1)%9+1]=(dp[i][(j+a[i]-1)%9+1]+dp[i-1][j])%M;
}
}
for(int i=1;i<=9;i++){
cout<<dp[n][i]<<" ";
}
return 0;
}
边栏推荐
- ionic cordova项目修改插件
- Talking about how dataset and dataloader call when loading data__ getitem__ () function
- Install and configure Jenkins
- JS bright blind your eyes date selector
- The difference between SQL Server char nchar varchar and nvarchar
- Usage and usage instructions of JDBC connection pool
- keep-alive
- Leetcode: Shortest Word Distance II
- Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
- SQL Server learning notes
猜你喜欢

Thymeleaf uses background custom tool classes to process text

MySQL之CRUD

Bugku cyberpunk

How to paste the contents copied by the computer into mobaxterm? How to copy and paste

Fr exercise topic - simple question

Bubble sort, insert sort

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking

Mongdb learning notes

keep-alive

First PR notes
随机推荐
30岁汇源,要换新主人了
Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
[recruitment position] infrastructure software developer
DVWA range clearance tutorial
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Go learning ----- relevant knowledge of JWT
lvgl 显示图片示例
Severlet learning foundation
Easyocr character recognition
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
JMeter performance test: serveragent resource monitoring
Crud of MySQL
12 MySQL interview questions that you must chew through to enter Alibaba
sql server学习笔记
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Bugku's steganography
The elimination strategy of redis
P1451 calculate the number of cells / 1329: [example 8.2] cells
Good article inventory