Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; long long memo[1 << 18]; int n,m,k; map
> mp; int a[20]; long long dp(int mask){ if(__builtin_popcount(mask) == m){ return 0; } if(memo[mask] != -1){ // return memo[mask]; } long long res =0; for (int i = 0; i < n; i++) { if(mask & (1 << i)){ continue; } else{ int temp_mask = (mask | (1 << i)); pair
pir = mp[i]; if(mask & (1 << pir.first)){ res= max(res,dp(temp_mask) + pir.second + a[i]); } else{ res= max(res,dp(temp_mask) + a[i]); } } } return memo[mask] = res; } int main(){ cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { int x,y,z; cin >> x >> y >> z; x--; y--; mp[y] = make_pair(x,z); } memset(memo,-1,sizeof memo); cout << dp(0); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)