Dressing

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2964 Accepted Submission(s): 1291

Problem Description

Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K different combinations of dressing.

One day he wears his pants Nike, shoes Adiwang to go to school happily. When he opens the door, his mom asks him to come back and switch the dressing. Mom thinks that pants-shoes pair is disharmonious because Adiwang is much better than Nike. After being asked to switch again and again Wangpeng figure out all the pairs mom thinks disharmonious. They can be only clothes-pants pairs or pants-shoes pairs.

Please calculate the number of different combinations of dressing under mom’s restriction.

Input

There are multiple test cases.

For each case, the first line contains 3 integers N,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes.

Second line contains only one integer P(0≤P≤2000000) indicating the number of pairs which mom thinks disharmonious.

Next P lines each line will be one of the two forms“clothes x pants y” or “pants y shoes z”.

The first form indicates pair of x-th clothes and y-th pants is disharmonious(1≤x≤N,1 ≤y≤M), and second form indicates pair of y-th pants and z-th shoes is disharmonious(1≤y≤M,1≤z≤K).

Input ends with “0 0 0”.

It is guaranteed that all the pairs are different.

Output

For each case, output the answer in one line.

Sample Input

2 2 2 0 2 2 2 1 clothes 1 pants 1 2 2 2 2 clothes 1 pants 1 pants 1 shoes 1 0 0 0

Sample Output

8 6 5

题意

给你n件衣服,m件袜子,k个鞋子,然后会告诉你某件衣服和某件袜子不搭配,或者某件袜子和某个鞋子不搭配,然后问你,一共有多少种搭配方案

题解

大概是排列组合吧,因为每一个不协调的搭配关系都包含PANTS,那么我们用两个数组记录,有那些衣服和鞋子不能搭配这个pants,然后枚举,累加就好

详细看代码吧~

代码

int a[maxn],b[maxn];

int main()
{
int n,m,k;
while(cin>>n>>m>>k)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
if(n==0&&m==0&&k==0)
break;
string s1,s2;
int kk,mm;
int p;
RD(p);
while(p--)
{
cin>>s1>>kk>>s2>>mm;
if(s1[0]=='c')
a[mm]++;
if(s2[0]=='s')
b[kk]++;
}
LL ans=0;
REP_1(i,m)
{
ans+=(n-a[i])*(k-b[i]);
}
cout<<ans<<endl;
}
}

hdu 4451 Dressing 排列组合/水题的更多相关文章

  1. Uva11538 排列组合水题

    画个图就很容易推出公式: 设mn=min(m,n),mx=max(m,n) 对角线上: 横向:m*C(n,2) 纵向:n*C(m,2) 因为所有的C函数都是只拿了两个,所以可以优化下.不过不优化也过了 ...

  2. HDU 4451 Dressing

    HDU 4451 Dressing 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451 Description Wangpeng has ...

  3. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  4. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  5. HDU 5590 ZYB's Biology 水题

    ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  6. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  7. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. hdu 1018:Big Number(水题)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. hdu 2041:超级楼梯(水题,递归)

    超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

随机推荐

  1. C#基础学习之装箱,拆箱

    装箱,拆箱这两个的大条件是有继承关系. 装箱:值类型转换为引用类型 拆箱:引用类型转换为之类 但是要注意大条件. string (引用类型)  int(值类型)   这个转换因为没有继承关系,内存中没 ...

  2. C#.NET调用WSDL接口及方法

    1.首先需要清楚WSDL的引用地址 如:http://XX.XX.4.146:8089/axis/services/getfileno?wsdl 上述地址的构造为 类名getfileno. 2.在.N ...

  3. trace spring

    package xx.com.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotati ...

  4. Codeforces Round #505

    Codeforces Round #505 A. Doggo Recoloring 题目描述:给定一个字符串,每次选择一个在字符串里面出现至少两次的字符,然后将这种字符变成那一种指定的字符,问最终这个 ...

  5. java基础47 装饰着模式设计

    1.装饰者模式 增强一个类的功能,而且还可以让这些装饰类相互装饰 2.装饰者设计模式的步骤 1.在装饰类的内部维护一个被装饰类的引用    2.让装饰者有一个共同的父类或者父接口 3.实例 packa ...

  6. android解决AVD中文路径无法启动问题

    在as中新建一个AVD,然而启动时却报错,总之是不能找到中文路径 然后这个虚拟设备被默认安装在了C盘我的用户李敏啊,而我用户名是中文名导致无法识别 解决办法,使用链接文件格式修改虚拟设备配置路径, 比 ...

  7. 耗时任务DefaultEventExecutorGroup 定时任务

    一. 耗时任务 static final EventExecutorGroup group = new DefaultEventExecutorGroup(16); // Tell the pipel ...

  8. java多线程-读写锁原理

    Java5 在 java.util.concurrent 包中已经包含了读写锁.尽管如此,我们还是应该了解其实现背后的原理. 读/写锁的 Java 实现(Read / Write Lock Java ...

  9. const 和 #define区别_fenglovel_新浪博客

    const 和 #define区别 (2012-12-11 14:14:07) 转载▼ 标签: 杂谈   (1) 编译器处理方式不同 define宏是在预处理阶段展开. const常量是编译运行阶段使 ...

  10. android拾遗——Android 动画学习笔记

    3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...