HDU4451Dressing (count)

Source: Internet
Author: User

HDU4451Dressing (count)

HDU4451Dressing (count)

Question Link

N pieces of clothing, M trousers, and K pair of shoes. Now there is an unreasonable combination of P (clothes, trousers, pants, and shoes ), it is required that you do not need to use a combination of three pieces of clothing, trousers, and shoes.

Solution: if an unreasonable matching solution is provided, the total number of matching options is reduced by 2. but there may be clothes 1 pants 1, pants 1 shoes 1 and so on, so the clothes 1 pants 1 shoes 1 more than once. Because pants are associated here, the numbers of clothes and shoes that cannot be matched with each pair are recorded, and the trousers are enumerated at the end, accumulated on one side (N-the number of clothes that do not match this pair of trousers )? (K-shoes that are not fit with this pair of trousers)

Code:

#include 
  
   #include 
   
    const int maxn = 1e3 + 5;int vis1[maxn][maxn], vis2[maxn][maxn];int c[maxn], s[maxn];int main () {    int N, M, K, P;    int a, b;    char str1[10], str2[10];    while (scanf ("%d%d%d", &N, &M, &K) && (N || M ||K)) {        memset (vis1, 0, sizeof (vis1));        memset (vis2, 0, sizeof (vis2));        memset (c, 0, sizeof (c));        memset (s, 0, sizeof (s));        scanf ("%d", &P);        for (int i = 0; i < P; i++) {            scanf ("%s%d%s%d", str1, &a, str2, &b);            if (str1[0] == 'c' && str2[0] == 'p') {                if (!vis1[a][b]) {                    vis1[a][b] = 1;                    c[b]++;                }            }            if (str1[0] == 'p' && str2[0] == 's') {                if (!vis2[a][b]) {                    vis2[a][b] = 1;                    s[a]++;                }            }        }        int ans = 0;        for (int i = 1; i <= M; i++)            ans += (N - c[i]) * (K - s[i]);        printf ("%d\n", ans);    }    return 0;}
   
  

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.