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;}