当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
Create ASM disk through DD
Sample template of software design document - learning / practice
测试 CS4344 立体声DA转换器
VSCode的有用插件
Notes on the paper "cross view transformers for real time map view semantic segmentation"
How to build your own knowledge engine? Community open application
6-5 vulnerability exploitation SSH weak password cracking and utilization
Public inputs in appliedzkp zkevm (13)
Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
【QT】定时器
随机推荐
【MATLAB】MATLAB 仿真模拟调制系统 — VSB 系统
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
[matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
Zhongke panyun-d module analysis and scoring standard
【QT】定时器
QT qtableview data column width adaptation
Detailed comparison of Hynix emmc5.0 and 5.1 series
Roles of rollup components
[matlab] general function of communication signal modulation Fourier transform
【MATLAB】通信信号调制通用函数 — 傅里叶变换
How to build your own knowledge engine? Community open application
C basic (VII) document operation
[matlab] matlab simulation modulation system - DSB system
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
Daily question brushing record (12)
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调