当前位置:网站首页>Li Kou's 300th weekly match
Li Kou's 300th weekly match
2022-07-04 05:04:00 【leimingzeOuO】
Catalog
6108. Decrypt the message
class Solution {
public:
map<char,int>mp;
string decodeMessage(string key, string message) {
int cnt=0;
string s;
for(auto x:key)
if(!mp.count(x)&&x!=' ')mp[x]=cnt++;
for(auto x:message)
if(x==' ')s+=x;
else s+=mp[x]+'a';
return s;
}
};
6111. Spiral matrix IV
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
vector<vector<int>> spiralMatrix(int m, int n, ListNode* head) {
vector<vector<int>>v(m,vector<int>(n));
int row=0,col=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)v[i][j]=-1;
int l=0,r=n-1;
int t=0,b=m-1;
while(l<=r||t<=b)
{
for(int i=l;i<=r&&t<=b&&head;i++)v[t][i]=head->val,head=head->next;
t++;
for(int i=t;i<=b&&l<=r&&head;i++)v[i][r]=head->val,head=head->next;
r--;
for(int i=r;i>=l&&t<=b&&head;i--)v[b][i]=head->val,head=head->next;
b--;
for(int i=b;i>=t&&l<=r&&head;i--)v[i][l]=head->val,head=head->next;
l++;
}
return v;
}
};
6109. Number of people who know the secret
class Solution {
public:
int peopleAwareOfSecret(int n, int delay, int forget) {
const int mod=1e9+7;
vector<vector<int>>f(n+1,vector<int>(n+1));
for(int i=1;i<=forget;i++)f[1][i]=1;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=forget;j++)
{
if(j==1)f[i][j]=(f[i-1][forget-1]-f[i-1][delay-1])%mod;
else f[i][j]=(f[i-1][j-1]-f[i-1][j-2])%mod;
f[i][j]=(f[i][j]+f[i][j-1])%mod;
}
}
return (f[n][forget]+mod)%mod;
}
};
6110. The number of incremental paths in the grid graph
class Solution {
public:
int n,m;
const int N=1010,mod=1e9+7;
int f[1010][1010];
vector<vector<int>>g;
int dx[4]={
-1,0,1,0},dy[4]={
0,1,0,-1};
int dp(int x,int y)
{
int &v=f[x][y];
if(~v)return v;
v=1;
for(int i=0;i<4;i++)
{
int a=x+dx[i],b=y+dy[i];
if(a>=0&&a<n&&b>=0&&b<m&&g[a][b]>g[x][y])
v=(v+dp(a,b))%mod;
}
return v;
}
int countPaths(vector<vector<int>>& grid) {
n=grid.size(),m=grid[0].size();
g=grid;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
f[i][j]=-1;
int res=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
res=(res+dp(i,j))%mod;
return res;
}
};
边栏推荐
- Annex III: scoring standard of the defender docx
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
- 中職組網絡安全—內存取證
- [matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
- 附件二:攻防演练保密协议.docx
- COMP1721 Creating Classes
- Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
- 附件三:防守方评分标准.docx
- We believe that the development of consumer Internet will still be limited to the Internet industry itself
- Roles of rollup components
猜你喜欢

测试 CS4344 立体声DA转换器

KMP匹配字符串

【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre

中科磐云—模块A 基础设施设置与安全加固 评分标准

Technology Management - learning / practice

Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard

Notes on the paper "cross view transformers for real time map view semantic segmentation"

Use units of measure in your code for a better life

如何构建属于自己的知识引擎?社群开放申请

Download kicad on Alibaba cloud image station
随机推荐
Secondary vocational group network security - memory Forensics
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
Rollup各组件作用
PostgreSQL 正式超越 MySQL,这家伙也太强了吧!
2022年6月总结
YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)
Daily question brushing record (12)
cmake
由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
【MATLAB】MATLAB 仿真模拟调制系统 — VSB 系统
Capturing and sorting out external Fiddler -- Conversation bar and filter
The second case analysis of the breakthrough of defense system from the perspective of the red team
NTFS security permissions
小程序毕业设计---美食、菜谱小程序
全国职业院校技能大赛(中职组)网络安全竞赛试题—解析
June 2022 summary
How to build your own knowledge engine? Community open application
Sécurité du réseau dans les écoles professionnelles secondaires - preuve de mémoire
[matlab] matlab simulation modulation system - DSB system