diff --git a/problem-of-the-day/day15/Best Time to Buy and Sell Stock with Transaction Fee.cpp b/problem-of-the-day/day15/Best Time to Buy and Sell Stock with Transaction Fee.cpp deleted file mode 100644 index 193f846..0000000 --- a/problem-of-the-day/day15/Best Time to Buy and Sell Stock with Transaction Fee.cpp +++ /dev/null @@ -1,26 +0,0 @@ -class Solution { -public: -long long dp[100002][2]; - long long solve (vector& nums,int i,int flag,int k) - { - if(i>=nums.size())return 0; - long long take=0; - if(dp[i][flag]!=-1)return dp[i][flag]; - if(flag==0) - { - take+= max(nums[i]+f(nums,i+1,1,k),f(nums,i+1,flag,k)); - } - if(flag==1) - { - take+= max(-nums[i]-k+f(nums,i+1,0,k),f(nums,i+1,flag,k)); - //deductiong concession fee k - } - return dp[i][flag] = take; - - } - int maxProfit(vector& nums, int fee) { - memset(dp,-1,sizeof(dp)); - return f(nums,0,1,fee); - - } -}; \ No newline at end of file diff --git a/problem-of-the-day/day15/D_Knapsack_1.cpp b/problem-of-the-day/day15/D_Knapsack_1.cpp deleted file mode 100644 index 0879bf7..0000000 --- a/problem-of-the-day/day15/D_Knapsack_1.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; -#define ll long long - -// Time Complexity: O(n*w) - -int main() -{ - ll n , w ; - cin>>n>>w; - vectorweight(n) , value(n); - for(int i = 0 ; i>weight[i]>>value[i]; - } - vector>dp(n+1 , vector(w+1 , 0)); - for(int i = 1 ; i<=n ; i++) - { - for(int j = 1 ; j<=w ; j++) - { - if(weight[i-1] <= j) - { - dp[i][j] = max(dp[i][j] , value[i-1] + dp[i-1][j-weight[i-1]]); - } - dp[i][j] = max(dp[i][j] , dp[i-1][j]); - } - } - cout< - using namespace std; - #define ll long long - - // Time Complexity: O(n*sum(v)) - // IN dp[i][j] , we store the minimum weight required to get value j using first i items - - int main() - { - ll n , w ; - cin>>n>>w; - vectorweight(n) , value(n); - for(int i = 0 ; i>weight[i]>>value[i]; - } - ll sum = 0; - for(auto x : value) - { - sum+=x; - } - vector>dp(n+1 , vector(sum+1 , INT_MAX)); - dp[0][0] = 0; - for(int i = 1 ; i<=n ; i++) - { - for(int j = 0 ; j<=sum ; j++) - { - dp[i][j] = dp[i-1][j]; - if(j>=value[i-1]) - { - dp[i][j] = min(dp[i][j] , weight[i-1] + dp[i-1][j-value[i-1]]); - } - } - } - ll ans = 0; - for(int i = 0 ; i<=sum ; i++) - { - if(dp[n][i]<=w) - { - ans = i; - } - } - cout< -using namespace std; -#define ll long long - -int main() -{ - string a,b ; - cin>>a>>b; - ll s1 = a.size() ; - ll s2 = b.size() ; - vector>dp(s1 + 1 , vector(s2 + 1 , INT_MAX)) ; - for(int i = 0 ; i<=s1 ; i++) - { - dp[i][0] = i; - } - for(int i = 0 ; i<=s2 ; i++) - { - dp[0][i] = i; - } - for(int i = 1 ; i<=s1 ; i++) - { - for(int j = 1 ; j<=s2 ; j++) - { - dp[i][j] = min(dp[i][j],1 + dp[i-1][j]); - dp[i][j] = min(dp[i][j],1 + dp[i][j-1]); - dp[i][j] = min(dp[i][j] , (a[i-1]!=b[j-1]) + dp[i-1][j-1]); - } - } - // for(auto x : dp) - // { - // for(auto y : x) - // { - // cout<& nums) { - int n = nums.size(); - vectordp(n,1); - // dp[i] stores the length of longest increasing subsequence ending at i - for(int i = 1 ; i=0 ; j--) - { - if(nums[i]>nums[j]) - { - dp[i] = max(dp[i] , 1 + dp[j]); - } - } - } - return *max_element(dp.begin() , dp.end()); - } -}; \ No newline at end of file diff --git a/problem-of-the-day/day15/Longest Increasing Subsequence NlogN.cpp b/problem-of-the-day/day15/Longest Increasing Subsequence NlogN.cpp deleted file mode 100644 index d1774d3..0000000 --- a/problem-of-the-day/day15/Longest Increasing Subsequence NlogN.cpp +++ /dev/null @@ -1,27 +0,0 @@ -class Solution { -public: - // Time Complexity: O(nlogn) - // Space Complexity: O(n) - - int lengthOfLIS(vector& nums) { - int n = nums.size() ; - vectorlis; - lis.push_back(nums[0]); - for(int i = 0 ; i> dp(N, vector(N)); - - // Initialize the main diagonal to 0 - for (int i = 1; i < N; i++) { - dp[i][i] = 0; - } - - // L is the chain length - for (int len = 2; len < N; len++) { - for (int i = 1; i < N - len + 1; i++) { - int j = i + len - 1; - dp[i][j] = INT_MAX; - for (int k = i; k <= j - 1; k++) { - int q = dp[i][k] + dp[k + 1][j] + arr[i - 1] * arr[k] * arr[j]; - dp[i][j] = min(dp[i][j], q); - } - } - } - - return dp[1][N - 1]; - } -}; \ No newline at end of file