当前位置:网站首页>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;
}
边栏推荐
- 做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
- Install PHP extension spoole
- Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
- 漫画:优秀的程序员具备哪些属性?
- lvgl 显示图片示例
- Usage and usage instructions of JDBC connection pool
- Common MySQL interview questions
- 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?
- JS bright blind your eyes date selector
- 华为哈勃化身硬科技IPO收割机
猜你喜欢
随机推荐
爱可可AI前沿推介(7.5)
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
Fr exercise topic - simple question
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
B站做短视频,学抖音死,学YouTube生?
[recruitment position] infrastructure software developer
Ctfshow web entry command execution
机器学习框架简述
复现Thinkphp 2.x 任意代码执行漏洞
P6183 [USACO10MAR] The Rock Game S
Can gbase 8A view the location of SQL statement history?
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
Bubble sort, insert sort
Bugku's Ping
Appium自动化测试基础 — APPium基础操作API(二)
Machine learning notes - gray wolf optimization
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
Go learning ----- relevant knowledge of JWT
mapper. Comments in XML files



![1330: [example 8.3] minimum steps](/img/69/9cb13ac4f47979b498fa2254894ed1.gif)





