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
using namespace std; char mat[22][22]; int n; int dp[1 << 21]; int rec(int bitmask) { if(__builtin_popcount(bitmask) == n ) { return 0; } if(dp[bitmask] != -1) { return dp[bitmask]; } int res = 2e9; for(int i = 0; i < n; i++) { if(bitmask & (1 << i)) continue; int c = 0; for(int j = 0; j < n; j++) { if(bitmask & (1 << j)) { if(mat[i][j] == 'D') { c++; } } } res = min(res, rec(bitmask | (1 << i)) + c); } return dp[bitmask] = res; } int main() { ios_base::sync_with_stdio(false); cin >> n; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cin >> mat[i][j]; } } memset(dp, -1, sizeof dp); cout << rec(0) << endl; return 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)