Hdu 4451 Dressing (简单容斥)
2014-03-30 10:10
483 查看
题意:有N种衣服,M种裤子和K种鞋子,已知哪些衣服和哪些裤子不能搭配,哪些裤子和哪些鞋子不能搭配,现在要选择一套(衣服+裤子+鞋子),问有多少种搭配方法。
思路:所有的不和谐搭配都是与裤子有关的,所以分别统计对于一条裤子哪些衣服和鞋子不和谐,减掉相应的数量,再加上多减去的,详见代码。
思路:所有的不和谐搭配都是与裤子有关的,所以分别统计对于一条裤子哪些衣服和鞋子不和谐,减掉相应的数量,再加上多减去的,详见代码。
#include <cstdio> #include <cstring> int clothes[1005], shoes[1005]; int main () { int n,m,k; while (~scanf("%d%d%d",&n,&m,&k),n||m||k) { memset(clothes,0,sizeof(clothes)); memset(shoes,0,sizeof(shoes)); int cnt; scanf("%d",&cnt); char s1[10],s2[10]; int a,b,i; while (cnt--) { scanf("%s%d%s%d",s1,&a,s2,&b); if (strcmp(s1, "clothes") == 0) clothes[b]++; else shoes[a]++; } int ans=n*m*k; for (i=1;i<=m;i++) { ans-=(clothes[i]*k); ans-=(shoes[i]*n); } for (i=1;i<=m;i++) ans+=clothes[i]*shoes[i]; printf("%d\n", ans); } return 0; }
相关文章推荐
- HDU 4451 简单容斥
- HDOJ 4451 - Dressing 简单容斥..
- HDU-#4451 Dressing(枚举)
- HDU - 4451 Dressing
- HDU 4451 Dressing
- hdu 4451 Dressing
- HDU-4451-Dressing (2012年金华赛区J题)
- HDU 4451 Dressing(计数)
- HDU 1796How many integers can you find(简单容斥定理)
- HDU 4451 Dressing
- HDU 4451 Dressing
- HDU 1796How many integers can you find(简单容斥定理)
- HDU-4451-Dressing (2012年金华赛区J题)
- hdu 4451 Dressing
- Hdu 4451 Dressing
- hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1
- 第37届ACM/ICPC 金华赛区现场赛最水四道题 HDU 4442 Physical Examination HDU 4450 Draw Something HDU 4451 Dressing HDU 4452 Running Rabbits
- 【HDU 4451 Dressing】水题,组合数
- hdu 4451 简单题
- HDU 1796How many integers can you find(简单容斥定理)