Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution of problem 1 : CPP #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}
47 changes: 47 additions & 0 deletions Problem Statement 1/mohitProb1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define double long double
#define pb push_back
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(v) (int)v.size()
#define deb(x) cout << #x << "=" << x << endl;

const int mod = 1e9 + 7;
const int mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795;

//EXPLAINATION :

//the number n is between 0 < x < n, so it can't hold value equal to 0 and n.
// so if we take example of n=4 (even), then only value x=1,2,3 exists, which means only Anuj won 1 and avni won 1, then anuj won 2 , and avni has no more moves.
// hence anuj won and true is returned

// consider n=3(odd), then only values x=1,2 exists, which means anuj won 1, then avni won 1 and then moves are over. so anuj did'nt won last match
// so he lost and false is returned.


int solve(int x)
{
if(x%2==0){
// cout<<"yes"<<endl;
return true;
}
else{
// cout<<"no"<<endl;
return false;
}


}


int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n; cin>>n;
solve(n);

}
54 changes: 54 additions & 0 deletions Problem Statement 2/mohitProb2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define double long double
#define pb push_back
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(v) (int)v.size()
#define deb(x) cout << #x << "=" << x << endl;

const int mod = 1e9 + 7;
const int mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795;

//EXPLAINATION :

//here we have 5 characters, and we need to output pairs of string on increasing the value of n
// for n=1, we get a,e,i,o,u, which means output : 5 (numbers)
//for n=2, we get ["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"]., we get 15 strings so output = 15

// so simply, if we suppose every vowel equal to 1, and we sum it up, on every iteration till n==0, then we get the solution,
// it is because it simply calculates the pairs, so for n=1, it got 5, so if we are finding n=2, the data will iterate from 2 to 0, so the answer will be
//will be 15


int solve(int x)
{
int a=1,e=1,i=1,o=1,u=1;

while(x--){
a=a;
e= e +a;
i= i+e;
o= o+i;
u= u+o;


}
// cout<<a+e+i+o+u<<endl;

return a+e+i+o+u;


}


int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n; cin>>n;
solve(n);

}
48 changes: 48 additions & 0 deletions Problem Statement 3/mohitProb3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define double long double
#define pb push_back
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(v) (int)v.size()
#define deb(x) cout << #x << "=" << x << endl;

const int mod = 1e9 + 7;
const int mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795;

//EXPLAINATION :

// in this problem, I used DP. basically I am creating an array that keeps the max solution stored.
//in addition to it, I have added two variables, namely current_max and current_sol, so we are checking the value iteratively and
//keeping the value stored
// at the end we are returning the sum of elements of maximum array created



int solve(vector<int>&v, int k)
{
int n = v.size();
vector<int> letsUseDP(n+1, 0);

for(int i=1; i<=n; i++){
int current_sol = 0;
int current_max = 0;


for(int j=1; j<=k && i-j>=0; j++){
current_max = max(current_max, v[i-j]);
current_sol = max(current_sol, letsUseDP[i-j] + current_max * j);
}
letsUseDP[i] = current_sol;
}

// cout<<dp[n];
return letsUseDP[n];



}