当前位置:网站首页>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;
}
边栏推荐
- Number protection AXB function! (essence)
- Common PHP interview questions (1) (written PHP interview questions)
- Install PHP extension spoole
- [JVM] operation instruction
- Thymeleaf uses background custom tool classes to process text
- episodic和batch的定义
- qt creater断点调试程序详解
- Can gbase 8A view the location of SQL statement history?
- [12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
- Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
猜你喜欢
随机推荐
go学习 ------jwt的相关知识
Usage and usage instructions of JDBC connection pool
Can gbase 8A view the location of SQL statement history?
JS bright blind your eyes date selector
1330: [example 8.3] minimum steps
Install PHP extension spoole
可转债打新在哪里操作开户是更安全可靠的呢
Appium自动化测试基础 — APPium基础操作API(二)
JMeter performance test: serveragent resource monitoring
Creation and optimization of MySQL index
Fr exercise topic --- comprehensive question
Redis distributed lock principle and its implementation with PHP (1)
Bubble sort, insert sort
Redis' transaction mechanism
I spring and autumn blasting-2
lv_font_conv离线转换
Mongdb learning notes
ionic cordova项目修改插件
Can I pass the PMP Exam in 20 days?
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
![[JVM] operation instruction](/img/f5/85580495474ef58eafbb421338e93f.png)








