Ultraviolet A 818-Cutting Chains (violent)

Source: Internet
Author: User

Link: Ultraviolet A 818-Cutting Chains


The following figure shows some links and links that are connected to each other. You can connect these rings at least when you open them. Note that they are not rings.


Solution: Because n is only 15 at the maximum, you can use a binary number to indicate whether each ring is opened, and then determine whether there is a location degree greater than 2, and whether there is a ring.


#include 
 
  #include 
  
   #include 
   
    #include using namespace std;const int N = 20;int n, ans, k, ti, g[N][N];void init() {ans = n;int a, b;memset(g, 0, sizeof(g));while (scanf("%d%d", &a, &b) == 2) {if (a == -1 || b == -1) break;g[a-1][b-1] = g[b-1][a-1] = 1;}}int cal(int s) {return s ? cal(s/2) + (s&1) : 0;}bool judge() {for (int i = 0; i < n; i++) {if (k & (1<
    
      2) return true;}return false;}bool dfs(int f, int u, int* vis) {if (vis[u]) return true;vis[u] = 1;for (int i = 0; i < n; i++) {if (k & (1<
     
      = ti - 1) {ans = min(ans, cal(k));}}int main() {int cas = 1;while (scanf("%d", &n) == 1 && n) {init();for (k = 0; k < (1<
      
       

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.