小
what? Sorry,My English isn't good.
Anonymous
Why do you send it here? Why should we know?
小
I want to learn
Anonymous
https://www.youtube.com/watch?v=UdTzHmjMYBc
Anonymous
Samvel
hi, can anyone tell / show a code example a combined way to sort by insertion and merge?
Hi
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=300005;
int cnt,head[maxn],n,m,now;
int in[maxn],dp[maxn][26];
char s[maxn];
vector<int> ans;
struct node{
int to,next;
}e[maxn*2];
void add(int u,int v){
e[cnt].to=v;
e[cnt].next=head[u],head[u]=cnt++;
}
void init(){
memset(head,-1,sizeof(head));
cnt=0;
}
int topo(){
queue<int> q;
int now=0;
for(int i=1;i<=n;i++){
if(!in[i]){
q.push(i);
dp[i][s[i]-'a']++;
}
}
while(!q.empty()){
int u=q.front(); q.pop();
now++;
for(int i=head[u];~i;i=e[i].next){
int t=e[i].to,add=s[t]-'a';
for(int j=0;j<26;j++){
dp[t][j]=max(dp[t][j],dp[u][j]+(j==add?1:0));
}
if(--in[t]==0){
q.push(t);
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=0;j<26;j++)
ans=max(ans,dp[i][j]);
}
if(now!=n) return -1;
return ans;
}
int main(){
init();
int x,y;
scanf("%d%d%s",&n,&m,s+1);
for(int i=1;i<=m;i++){
scanf("%d%d",&x,&y);
add(x,y);
in[y]++;
}
printf("%d\n",topo());
return 0;
}
Can anyone convert this to python code
Rberto
Anonymous
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=300005;
int cnt,head[maxn],n,m,now;
int in[maxn],dp[maxn][26];
char s[maxn];
vector<int> ans;
struct node{
int to,next;
}e[maxn*2];
void add(int u,int v){
e[cnt].to=v;
e[cnt].next=head[u],head[u]=cnt++;
}
void init(){
memset(head,-1,sizeof(head));
cnt=0;
}
int topo(){
queue<int> q;
int now=0;
for(int i=1;i<=n;i++){
if(!in[i]){
q.push(i);
dp[i][s[i]-'a']++;
}
}
while(!q.empty()){
int u=q.front(); q.pop();
now++;
for(int i=head[u];~i;i=e[i].next){
int t=e[i].to,add=s[t]-'a';
for(int j=0;j<26;j++){
dp[t][j]=max(dp[t][j],dp[u][j]+(j==add?1:0));
}
if(--in[t]==0){
q.push(t);
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=0;j<26;j++)
ans=max(ans,dp[i][j]);
}
if(now!=n) return -1;
return ans;
}
int main(){
init();
int x,y;
scanf("%d%d%s",&n,&m,s+1);
for(int i=1;i<=m;i++){
scanf("%d%d",&x,&y);
add(x,y);
in[y]++;
}
printf("%d\n",topo());
return 0;
}
Can anyone convert this to python code
/warn read the rules
Ammar
It's a trivial question. The answer is very easy to be found on Google.
jcw
Yeah . I've already google.. but when i wanna use it in coding im a bit blur. .
Anonymous
jcw
....
Ooh so here I've to ask question only regarding C and C++ and for them also there are some rules.
....
Ok so understood now👍
armandofsanchez
Do you use shmget and shmat in c or are there better libreries for segment memory programming in linux?
AKILA
🤓 today I started learning c and how to major that ? Plz DM me.. 💕💕
AKILA
@K11M1 thnx
klimi
@K11M1 thnx
But if you needed something genuenly that is connected to c++ or c you can ask here, if it is something not c or c++ related you can try chatting the offtopic group :)
AKILA
What are the differents between c and c++
Rberto
AKILA
Rberto
klimi
Talula
Rberto
klimi
that's not right!
If you say so ¯\_ (ツ) _/¯ I would prefer this discussion to be in the offtopic group tho, thank you
Nameful
Nameful
Anonymous
AKILA
Thanx everyvody
AKILA
Talula
Larry
/get learn
Veronica
Best lol🤣🤣🤣
AKILA
😆😆
Sandeep
class Entity
{
public:
int x, y;
Entity (int x, int y)
{
Entity*& const e = this;
x = x;
}
Sandeep
In the tutorial he said..we can't assign this to something that is not comstanr
Sandeep
Here...after apemsand..there is const keyword
Sandeep
Then what's wrong with the line
Talula
Sandeep
Anonymous
Anonymous
Use books to learn C++
Not some silly tutorials
Sandeep
There is const keyword after ampersand ..that means it is a constant reference right
Anonymous
Anonymous
References are always constant
Sandeep
Everything
In the tutorial also he said it doesn't work..but I don't get why..
Anonymous
Sandeep
I googled it every where bruh..couldn't find anything
Anonymous
Sandeep
class Entity
{
public:
int x, y;
Entity (int x, int y)
{
/* But this line works...*/
Entity* const & e = this;
}
x = x;
Sandeep
How come this is a const reference and not the previous one🥺
Anonymous
Anonymous
There's no such thing as non const reference
Anonymous
There are references to constants and non-constants but every reference by itself is constant
сумбула
Anonymous
Sandeep
Sandeep
Or did I
сумбула
@Sandeep_ranweer pointers and reference can be very confusing first try to read more about them from books to understand them properly (personal advice)
Sandeep
Sure tq..
сумбула
Sandeep
Anonymous
Yes
In section 20 of c++ programming language
I saw something like this
Class name:int or vector
I thought class : base class
What is this
Anonymous
Anonymous
And I prefer not to speak to Nazis
Anonymous
As you wish you are admin
Anonymous
Ehsan
The Shadow Monarch
/tr eng
Ehsan
/tr