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
Danya🔥
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
klimi
Jer
Ik, I didn't read absolutely everything but I was in agreement
Jer
I've never even heard of dafny tbh
Jer
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
VD
Ольга
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++?
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
klimi
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🔥
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;
}
The problem is definitely not a time constant
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🔥
M
its given in the question
M
actual one not my interpretation
Ludovic 'Archivist'
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
Danya🔥
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.
Danya🔥
M
Ludovic 'Archivist'
Ludovic 'Archivist'
Start from the case where you pick the entire list
Danya🔥
Danya🔥
M
Danya🔥
Danya🔥
Now it's 45
M
Ludovic 'Archivist'
I edited
I guess we are the same flavour of tired
Danya🔥
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
Danya🔥
Ludovic 'Archivist'
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
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