klimi
@K11M1 what do you think?
not sure yet, not enough context
Danya🔥
Ludovic 'Archivist'
This is the first task
Start by printing the string normally, then in a second step, write the string while replacing the flags with the name of what they represent, then modify that code to handle flag types one by one
.
Am just an amateur in c but the way you answers you makes the feel like...
klimi
Am I useless?😢
Well i think that in this matter just saying "use chatgpt" is not much useful
.
Thank you for your help I want nothing anymore
Ludovic 'Archivist'
Thank you for your help I want nothing anymore
I gave you the iterative steps to work with, now behave like a normal human and fold. ChatGPT is terrible at programming, unless the language you require to use is Dafny
Jer
I gave you the iterative steps to work with, now behave like a normal human and fold. ChatGPT is terrible at programming, unless the language you require to use is Dafny
Bro chatgpt is terrible, I've used it, sometimes it works and sometimes it doesn't, it's a tool for learning, not a tool for work lol
Jer
Ik, I didn't read absolutely everything but I was in agreement
Ludovic 'Archivist'
Bro chatgpt is terrible, I've used it, sometimes it works and sometimes it doesn't, it's a tool for learning, not a tool for work lol
The only language it is good at is dafny, and that is because 99.99% of the dafny code out there is correct so it didn't learn stupid things
Jer
I've never even heard of dafny tbh
Ludovic 'Archivist'
I've never even heard of dafny tbh
https://dafny.org I am waiting for a better C++ backend before I dedicate a significant time to learn it well
Ludovic 'Archivist'
For your fiverr that you have in your bio... I'm intrigued
I teach programming, generally with C++, but I also taught C#, Java, JS, C, and most of the C family of languages in general
Jer
I wanna learn javascript too tbh
Jer
And C, and I already know the basics of C++ I think, just want to expand on that
VD
Madhu, I found out what you suggested earlier https://m.youtube.com/watch?v=8C8NnE1Dg4A&pp=ygUgQ3BwY29uIGNvcm91dGluZXMgdW5kZXIgdGhlIGhvb2Q%3D This covers exactly the things you said about stackful vs stackless
VD
Strange, I am not able to tag Madhu here
Ludovic 'Archivist'
Strange, I am not able to tag Madhu here
Hey, Madhu left the server because they stopped using C++ a while ago and didn't feel like staying after they left the moderation team
Ольга
Good evening! I have another question about matrices. I need to make a detour along the side diagonal. But my roots are not exact now in my code. I would be grateful for any explanation of what is wrong https://onlinegdb.com/4iMGuKArh
Supriyo
Any web crawler tutorial in c/c++?
Ziky
Any web crawler tutorial in c/c++?
https://duckduckgo.com/?t=ffab&q=Any+web+crawler+tutorial+in+c%2Fc%2B%2B%3F&ia=web
Brown Sedjara
Please how do i develop my c++ code into an app
Astro
you can use Qt C++ library or MFC
Anonymous
Is any one here speak english fluent
Rose
Is any one here speak english fluent
User Mustafa has 1/2 warnings; be careful! Reason: meta question and offtop right after join
Danya🔥
@nanoric sorry
Danya🔥
It is automatic stupid bot
Danya🔥
M
An array is given, you need to find the maximum sum of k elements from the array rules of choosing an element; - an element can be either the leftmost one or the rightmost one, after selecting it double the value of rest of the elements, afterthat select the next element; I was unable to pass the last testcase, so can anyone help to optimize the code. The testcase is hidden, and i think the problem is the time constraint, please help me to optimize it vector 'a' contains the scores; k - no. of elements to be choosen n - size of the vector CODE: long long int solve(vector<int> &a, int n, int k, vector<vector<vector<long long int>>> &dp,long long int cnt, int i, int j) { if (k==0) { return 0; } if (dp[i][j][k]!=-1) { return dp[i][j][k]; } long long int score1 = solve(a,n,k-1,dp,cnt<<1,i+1,j)+(a[i]*(cnt>>1)); long long int score2 =solve(a,n,k-1,dp,cnt<<1,i,j-1)+(a[j]*(cnt>>1)); return dp[i][j][k] = max(score1, score2); } int maxScore(int n, int k, vector<int> &a) { vector<vector<vector<long long int>>> dp(n,vector<vector<long long int>>(n,vector<long long int>(k+1,-1))); long long int result = solve(a,n,k,dp,2,0,n-1); return result%1000000007; }
Danya🔥
Your space complexity is at least O(n³) Why, just why?
Ludovic 'Archivist'
Yeah, it can clearly be optimized, and probably should use more standard algorithms
Danya🔥
Well, I've not read the whole assignment, yet it's still an overkill
Danya🔥
M
its the only approach i got, first i go with only recursion, then it passed only 2 test cases, then i used dp then it passed all the testcases, but i am stuck now
M
its a question which i was unable to solve in a contest
Danya🔥
its a question which i was unable to solve in a contest
It's not the answer to my question..
M
its given in the question
M
actual one not my interpretation
Ludovic 'Archivist'
its the only approach i got, first i go with only recursion, then it passed only 2 test cases, then i used dp then it passed all the testcases, but i am stuck now
First clue: do not actually multiply the elements, do not mutate the array Second clue: use iterators, they are pretty good Last clue: std::span is pretty good
Ludovic 'Archivist'
Oh, one last clue, you want to consume the biggest numbers last, no need for much trial and error
M
but i need to consume in a specific order which is different each time , which can be found only through traversal of all possible cases i.e recursion
Ludovic 'Archivist'
M
still cant get it
Danya🔥
You just have 2 pointers on both ends. You pick the smallest number, multiply it needed number of times and add to the resulting number. Then, you move pointer of the selected element one step closer to the center of the array. You repeat it K times.
Ludovic 'Archivist'
That is because for n<m, 2*n + 4*m > 4*n + 2*m
that is because, with n, m, and d natural numbers, n+d=m 2n+2d+4m = 4n+4d+2m So 2n+4m < 4n+2m because 2d < 4d
Ludovic 'Archivist'
Ludovic 'Archivist'
Start from the case where you pick the entire list
M
this is not possible if the test case is like this 5 3 9 1 5 4 1 the answer is 45 first 1 is chosen, then 8(4*2), then 27(9*3)
sorry its 9*4 , after selecting 1 it gets 18, and after selecting 4 it gets 36 so 1+8+36
Ludovic 'Archivist'
1 + 4*2 + 9*2*2 = 45
Yeah, I got the same answer
Danya🔥
Now it's 45
Ludovic 'Archivist'
I edited
I guess we are the same flavour of tired
Danya🔥
1+4*2+9*2*2
So? What's the correct answer?
M
45
Danya🔥
So the algorithm works
Danya🔥
Because it gives the same answer
Ludovic 'Archivist'
So the algorithm works
My proposed algorithm does not actually work if you do not consume the entire list, but it is a good starting point to find the correct one
Ludovic 'Archivist'
Implement the case where you consume the entire list first
Abu
Hello....
Zidane
Guys i need to send photo
Zidane
#include<stdio.h> #include<stdlib.h> int main() { int number1,number2,number3,max,middle,min; printf("enter the first number:"); scanf("%d",&number1); printf("enter the second number:"); scanf("%d",&number2); printf("enter the third number:"); scanf("%d",&number3); if(number1>number2 && number1>number2){ max=number1; if(number2>number3){ number2=middle; number3=min; } if(number3>number2){ number2=min; number3=middle;}} else if(number2>number1 && number2>number3){ max=number2; if(number3>number1){ number3=middle; number1=min;} else if(number1>number3){ number3=min; number1=middle;}} else{ max=number3; if(number2>number1){ number2=middle; number1=min; } if(number1>number2){ number1=middle; number2=min;}} printf("max:%d\n",max); printf("middle:%d\n",middle); printf("min:%d\n",min); printf("arrangement of numbers: %d>%d>%d",max,middle,min); return 0; }
Zidane
okay its not working what can ı do
aklil
sorry its 9*4 , after selecting 1 it gets 18, and after selecting 4 it gets 36 so 1+8+36
can you elaborate your question more clearly, i have a spare time and i like problems like this
M
can you elaborate your question more clearly, i have a spare time and i like problems like this
Its like an array is given we can choose either the leftmost element or rightmost , and it to the sum variable and the double all the remaining elements of the array
M
TEST CASE i/p-> n=5,k=3 arr= 9,1,5,4,1 o/p->45 explanation: first element chosen is rightmost 1, then all rest of the elements are doubled sum+=1; new array=18,2,10,8 then select second element rightmost 8 in new array, then all rest of the elements are doubled sum+=8 new array=36,4,20 now leftmost element 36 sum+=36 so sum=45