当前位置:网站首页>2327. 知道秘密的人数(递推)
2327. 知道秘密的人数(递推)
2022-07-06 04:11:00 【Harris-H】
2327. 知道秘密的人数(递推)
一维dp就可以qwq。令 f i f_i fi表示第 i i i天新知道秘密的人数。
第 i i i天可以由 ( i − f o r g e t , i − d e l a y ] (i-forget,i-delay] (i−forget,i−delay] 递推。
显然可以预处理前缀和,做到 O ( n ) O(n) O(n)
最后的答案就是: ∑ i = n − f o r g e t + 1 n f i \sum\limits_{i=n-forget+1}^n f_i i=n−forget+1∑nfi
class Solution {
const int MOD = 1000000007;
public:
int peopleAwareOfSecret(int n, int delay, int forget) {
vector<long long> f(n + 1), g(n + 1);
f[1] = g[1] = 1;
for (int i = 2; i <= n; i++) {
int L = max(0, i - forget);
int R = max(0, i - delay);
f[i] = (g[R] - g[L] + MOD) % MOD;
g[i] = (g[i - 1] + f[i]) % MOD;
}
return (g[n] - g[max(0, n - forget)] + MOD) % MOD;
}
};
边栏推荐
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Proof of Stirling formula
- Mysql数据库慢sql抓取与分析
- Path of class file generated by idea compiling JSP page
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- DM8 archive log file manual switching
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
猜你喜欢

Cross domain and jsonp details

查询mysql数据库中各表记录数大小

自动化测试的好处

MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0

Custom event of C (31)

20、 EEPROM memory (AT24C02) (similar to AD)

Figure application details
![[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos](/img/41/27ce3741ef29e87c0f3b954fdef87a.png)
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos

【可调延时网络】基于FPGA的可调延时网络系统verilog开发

Data processing methods - smote series and adasyn
随机推荐
In depth MySQL transactions, stored procedures and triggers
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
VPP性能测试
51nod 1130 n factorial length V2 (Stirling approximation)
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
About some basic DP -- those things about coins (the basic introduction of DP)
C form application of C (27)
1291_Xshell日志中增加时间戳的功能
查询mysql数据库中各表记录数大小
记一次excel XXE漏洞
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
【leetcode】1189. Maximum number of "balloons"
解决“C2001:常量中有换行符“编译问题
Web components series (VII) -- life cycle of custom components
脚本生命周期
Lora gateway Ethernet transmission
Chinese brand hybrid technology: there is no best technical route, only better products
DM8 archive log file manual switching
HotSpot VM
Explain in simple terms node template parsing error escape is not a function