Computer Science & Engineering Computer Science & Engineering
Computer Science & Engineering Computer Science & Engineering
Experiment 3.1
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
while(t--){
ll n,k,x;
cin>>n>>k>>x;
vector<ll> path(n+1),dp(n+1);
path[1]=1;
if(x==1)
dp[1]=1;
else
dp[1]=0;
for(ll i=2;i<=n;i++){
path[i]=(path[i-1]*(k-1))%MOD;
dp[i]=(path[i-1]-dp[i-1]+MOD)%MOD;
}
cout<<dp[n]<<endl;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return 0;
}
Result:
b) #include <bits/stdc++.h>
using namespace std;
int mn = INT_MAX;
for (int i = 0; i < arr.size(); i++) mn = min(mn, arr[i]);
int k, ope, ans = INT_MAX;
for (int j = 0; j < 5; j++){
ope = 0;
for (int i = 0; i < arr.size(); i++){
k = arr[i] - mn;
ope += (k / 5) + (k % 5) / 2 + (k % 5) % 2;
}
ans = min(ans, ope);
mn--;
}
return ans;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string t_temp;
getline(cin, t_temp);
int t = stoi(ltrim(rtrim(t_temp)));
int n = stoi(ltrim(rtrim(n_temp)));
string arr_temp_temp;
getline(cin, arr_temp_temp);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
vector<int> arr(n);
arr[i] = arr_item;
}
fout.close();
return 0;
}
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);
return s;
}
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);
return s;
}
string::size_type start = 0;
string::size_type end = 0;
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Result:
Learning Outcome
• Learned about dynamic programmming
• Dynamic programming is especially useful for problems that
exhibit overlapping subproblems, where the same
subproblem is solved multiple times
• Dynamic programming can be categorized into two main
approaches: top-down (memoization) and bottom-up
(tabulation). and searching for specific characters or
substrings within the string