当前位置:网站首页>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;
}
边栏推荐
- Select sort and bubble sort
- Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
- Magic methods and usage in PHP (PHP interview theory questions)
- 可转债打新在哪里操作开户是更安全可靠的呢
- mapper.xml文件中的注释
- I include of spring and Autumn
- Leetcode: Shortest Word Distance II
- Coding devsecops helps financial enterprises run out of digital acceleration
- Stm32+bh1750 photosensitive sensor obtains light intensity
- Huawei Hubble incarnation hard technology IPO harvester
猜你喜欢
1330:【例8.3】最少步数
First PR notes
华为哈勃化身硬科技IPO收割机
超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜
Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de
Ionic Cordova project modification plug-in
Bugku easy_ nbt
I spring and autumn blasting-1
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Appium自动化测试基础 — APPium基础操作API(二)
随机推荐
Super wow fast row, you are worth learning!
Detailed explanation of QT creator breakpoint debugger
Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
MySQL表字段调整
Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de
Misc Basic test method and knowledge points of CTF
Leetcode: Shortest Word Distance II
Select sort and bubble sort
Go learning ----- relevant knowledge of JWT
Creation and optimization of MySQL index
Interpretation of Apache linkage parameters in computing middleware
Brief introduction of machine learning framework
Good article inventory
想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
Common MySQL interview questions (1) (written MySQL interview questions)
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Ctfshow web entry information collection
Huawei Hubble incarnation hard technology IPO harvester
B站做短视频,学抖音死,学YouTube生?
可转债打新在哪里操作开户是更安全可靠的呢