diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cba2e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/Problem Statement 1/mohitProb1.cpp b/Problem Statement 1/mohitProb1.cpp new file mode 100644 index 0000000..f4189c1 --- /dev/null +++ b/Problem Statement 1/mohitProb1.cpp @@ -0,0 +1,47 @@ +#include +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"<sync_with_stdio(0); + int n; cin>>n; + solve(n); + +} \ No newline at end of file diff --git a/Problem Statement 2/mohitProb2.cpp b/Problem Statement 2/mohitProb2.cpp new file mode 100644 index 0000000..eb50afd --- /dev/null +++ b/Problem Statement 2/mohitProb2.cpp @@ -0,0 +1,54 @@ +#include +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<sync_with_stdio(0); + int n; cin>>n; + solve(n); + +} \ No newline at end of file diff --git a/Problem Statement 3/mohitProb3.cpp b/Problem Statement 3/mohitProb3.cpp new file mode 100644 index 0000000..c256dc7 --- /dev/null +++ b/Problem Statement 3/mohitProb3.cpp @@ -0,0 +1,48 @@ +#include +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&v, int k) +{ + int n = v.size(); + vector 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<