-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreedy.cpp
More file actions
53 lines (40 loc) · 1.05 KB
/
Copy pathGreedy.cpp
File metadata and controls
53 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define loop(i, n) for(int i=0; i<(n); ++i)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pi;
/*
GREEDY GENERAL STRUCTURE
1) Initialize : res =0;
2) while(all itmes are not considered){
i = selectAnItem()
if(feasible(i)){
res = res + i
}
}
3) return res
*/
// min change problem
// EXCEPTION OCCURS !! > coins=[18, 1, 10], amount=20
int minCoins(vi& coins, int amount){
sort(coins.begin(), coins.end(), less<int>());
int cnt =0;
for(int coin : coins){
cnt += amount/coin;
amount%=coin;
}
return cnt;
}
// Activity Selection Problem
// Maximum # of activities that can happen on a single tasking machine.
int activitySelectionProblem(const vpi& activities){
}
int main(){
}