当前位置:网站首页>2327. Number of people who know secrets (recursive)
2327. Number of people who know secrets (recursive)
2022-07-06 04:15:00 【Harris-H】
2327. Number of people who know the secret ( Recurrence )
A one-dimensional dp Can qwq. Make f i f_i fi It means the first one i i i Tianxin knows the number of Secrets .
The first i i i Days can be controlled by ( i − f o r g e t , i − d e l a y ] (i-forget,i-delay] (i−forget,i−delay] Recurrence .
Obviously, prefixes and , Achieve O ( n ) O(n) O(n)
The final answer is : ∑ 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;
}
};
边栏推荐
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- Mlapi series - 04 - network variables and network serialization [network synchronization]
- Mixed development of QML and QWidget (preliminary exploration)
- Slow SQL fetching and analysis of MySQL database
- ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
- Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
- P2648 make money
- Basic use of MySQL (it is recommended to read and recite the content)
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- ESP32_ FreeRTOS_ Arduino_ 1_ Create task
猜你喜欢
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Slow SQL fetching and analysis of MySQL database
Mlapi series - 04 - network variables and network serialization [network synchronization]
User datagram protocol UDP
记一次excel XXE漏洞
One question per day (Mathematics)
DM8 archive log file manual switching
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
查询mysql数据库中各表记录数大小
10個 Istio 流量管理 最常用的例子,你知道幾個?
随机推荐
POI add border
Cross domain and jsonp details
Interface idempotency
Slow SQL fetching and analysis of MySQL database
Database, relational database and NoSQL non relational database
lora网关以太网传输
20、 EEPROM memory (AT24C02) (similar to AD)
Leetcode32 longest valid bracket (dynamic programming difficult problem)
TCP/IP协议里面的网关地址和ip地址有什么区别?
Lambda expression learning
Ipv4中的A 、B、C类网络及子网掩码
Detailed explanation of serialization and deserialization
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
Fundamentals of SQL database operation
Recommendation system (IX) PNN model (product based neural networks)
One question per day (Mathematics)
[FPGA tutorial case 11] design and implementation of divider based on vivado core
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
Path of class file generated by idea compiling JSP page