当前位置:网站首页>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;
}
边栏推荐
- Super wow fast row, you are worth learning!
- 30岁汇源,要换新主人了
- Magic methods and usage in PHP (PHP interview theory questions)
- Install PHP extension spoole
- MySQL 巨坑:update 更新慎用影响行数做判断!!!
- 计算中间件 Apache Linkis参数解读
- Anaconda uses China University of science and technology source
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
- First PR notes
- easyOCR 字符識別
猜你喜欢
随机推荐
First PR notes
【jvm】运算指令
Bugku's eyes are not real
Ionic Cordova project modification plug-in
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
当代人的水焦虑:好水究竟在哪里?
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
30岁汇源,要换新主人了
社区团购撤城“后遗症”
MySQL之CRUD
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
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
The elimination strategy of redis
How can the boss choose programmers to help me with development?
CSRF, XSS science popularization and defense
[recruitment position] infrastructure software developer
P6183 [USACO10MAR] The Rock Game S
Misc Basic test method and knowledge points of CTF
Stm32+bh1750 photosensitive sensor obtains light intensity
Common MySQL interview questions







![[JVM] operation instruction](/img/f5/85580495474ef58eafbb421338e93f.png)
