Codeforces|Leetcode|Codechef free solutions
Kanalga Telegramβda oβtish
Free codeforces, Codechef, Leetcode solutions are available ππππππ Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. π₯³π₯³π₯³π€©π€©π€© Dm @Cpsoln if you want help in coding round.
Ko'proq ko'rsatish4 317
Obunachilar
Ma'lumot yo'q24 soatlar
-137 kunlar
-5230 kunlar
Postlar arxiv
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int minTotalSum(const vector<int>& a, int k) {
int n = a.size();
vector<vector<int>> dp(n + 1, vector<int>(k + 1, 1e9));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
for (int x = max(0, i - 2); x < i; ++x) {
dp[i][j] = min(dp[i][j], dp[x][j - (i != n)] + a[x]);
}
}
}
int ans = 1e9;
for (int j = 0; j <= k; ++j) {
ans = min(ans, dp[n][j]);
}
return ans;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
cout << minTotalSum(a, k) << endl;
}
return 0;
}
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
#define endl "\n"
#define mod 1000000007
int32_t main()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
cin >> t;
while(t--){
int n;
cin >> n;
int a[n],f=0;
unordered_map<int,int>m;
for(int i=0; i<n; i++){
cin >> a[i];
m[a[i]]=i+1;
if(m[i+1]==a[i]){
f=1;
}
}
if(f){
cout<<2<<endl;
}
else{
cout<<3<<endl;
}
}
return 0;
}
Oa help available for any companies
Dm @Cpsoln before to book the slot.
Geeks for Geeks Job-a-thon slots available
Dm @Cpsoln
Google girls Hackathon all code done β
β
β
β
Dm @Cpsoln
