当前位置:网站首页>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;
}
边栏推荐
- P1451 calculate the number of cells / 1329: [example 8.2] cells
- Fr exercise topic - simple question
- queryRunner. Query method
- PHP high concurrency and large traffic solution (PHP interview theory question)
- 我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
- Ionic Cordova project modification plug-in
- Bugku's Ping
- 数学建模之层次分析法(含MATLAB代码)
- 亿咖通科技通过ISO27001与ISO21434安全管理体系认证
- sql server char nchar varchar和nvarchar的区别
猜你喜欢

Redis' transaction mechanism

数学建模之层次分析法(含MATLAB代码)

30岁汇源,要换新主人了

sql server学习笔记

Stop B makes short videos, learns Tiktok to die, learns YouTube to live?

Ctfshow web entry command execution

计算中间件 Apache Linkis参数解读

Coding devsecops helps financial enterprises run out of digital acceleration

No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle

Huiyuan, 30, is going to have a new owner
随机推荐
How can the boss choose programmers to help me with development?
Ten billion massage machine blue ocean, difficult to be a giant
Cartoon: programmers don't repair computers!
Can gbase 8A view the location of SQL statement history?
MySQL5.7的JSON基本操作
Install PHP extension spoole
Bugku's steganography
Thymeleaf uses background custom tool classes to process text
JMeter performance test: serveragent resource monitoring
PHP high concurrency and large traffic solution (PHP interview theory question)
"Sequelae" of the withdrawal of community group purchase from the city
SQL Server learning notes
Common PHP interview questions (1) (written PHP interview questions)
I spring web upload
JS bright blind your eyes date selector
ionic cordova项目修改插件
Misc Basic test method and knowledge points of CTF
Magic methods and usage in PHP (PHP interview theory questions)
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
I spring and autumn blasting-1