en
Feedback
Deloitte | PWC | ATS resumes | Wipro | Infosys | Accenture | Capegemini | job links

Deloitte | PWC | ATS resumes | Wipro | Infosys | Accenture | Capegemini | job links

Open in Telegram
4 673
Subscribers
No data24 hours
-17 days
-630 days
Posts Archive
I will share all codes Share our channel

from itertools import permutations def solve(A,K): def findDifference(num): cnt = 0 for i in range(len(num)): for j in range(i + 1, len(num)): cnt += abs(num[i] - num[j]) return cnt ans = list(permutations(A,K)) maxi = float('-inf') for i in ans: maxi = max(maxi, findDifference(i)) return maxi N = int(input()) K = int(input()) A = [int(input()) for _ in range(N)] print(solve(A,K)) // Dp or not Dp

#include <bits/stdc++.h> using namespace std; void solve(vector<vector<int>> vv, int operation, int xx, int yy, int &res) {     for (int i = 1; i < 3; i++)     {         int sum1 = 0;         for (int j = 0; j < vv.size(); j++)         {             sum1 += vv[j][i - 1];         }         int sum2 = 0;         for (int j = 0; j < vv.size(); j++)         {             sum2 += vv[j][i];         }         if (sum1 == sum2)         {             res = min(res, operation);         }         return;     }     for (int i = 0; i < vv.size(); i++)     {         solve(vv, operation, xx, yy, res);         vector<int> p1 = vv[i];         reverse(p1.begin(), p1.end());         solve(vv, operation + yy, xx, yy, res);         vector<int> p2 = vv[i];         int temp1 = p2[0];         int temp2 = p2[1];         int temp3 = p2[2];         p2[2] = temp1;         p2[1] = temp3;         p2[0] = temp2;         solve(vv, operation + xx, xx, yy, res);         vector<int> p3 = vv[i];         temp1 = p2[0];         temp2 = p2[1];         temp3 = p2[2];         p2[2] = temp2;         p2[1] = temp1;         p2[0] = temp3;         solve(vv, operation + xx, xx, yy, res);     }     return; } int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--)     {         int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, sum = 0, diff = 0, maxN = 0, minN = 0, count = 0, temp = 0;         bool flag = false;         cin >> n;         cin >> m;         int xx;         cin >> xx;         int yy;         cin >> yy;         vector<vector<int>> vv(n, vector<int>(m));         for (int i = 0; i < n; i++)         {             for (int j = 0; j < m; j++)             {                 cin >> vv[i][j];             }         }         if (n == 1)         {             cout << -1 << endl;             continue;         }         int res = INT_MAX;         solve(vv, 0, xx, yy, res);         cout << res << endl;     }     return 0; } // Pay for a gift

Infosys exam help available Only one slot left

Elitmus ph test help available Date -21st this SundayContact-@placementsBro😎 98+ score confirmhttps://t.me/Coding_palace/6273