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. Django 内置模板标签和过滤器

    一.内置模板标签 语法:{%  %} autoescape : 是否转义,on或off作为参数,并确定自动转义是否在块内有效.该块以endautoescape结束 {% autoescape on % ...

  2. Python和MySQL数据库交互PyMySQL

    Python数据库操作 对于关系型数据库的访问,Python社区已经指定了一个标准,称为Python Database API SepcificationV2.0.MySQL.Qracle等特定数据库 ...

  3. python网络编程--线程join和Daemon(守护进程)

    一:什么情况下使用join join([timeout])调用join函数会使得主调线程阻塞,直到被调用线程运行结束或超时. 参数timeout是一个数值类型,用来表示超时时间,如果未提供该参数,那么 ...

  4. 教您如何进行SQL跨表更新

    SQL跨表更新数据是在使用SQL数据库中比较常用的,下面就将为您详细介绍SQL跨表更新数据的步骤,希望对您学习SQL跨表更新数据有所启迪. 原始数据如下,首先是表结构 A_dept的初始数据 A_em ...

  5. SqlServr性能优化性能之层次结构(十五)

    1.添加根节点: hierarchyid  GetRoot()方法 --创建数据库 create table Employeeh(EmployeeID int,Name varchar(500),Ma ...

  6. java解析Xml格式的字符串

    最近在工作中,需要调别的接口,接口返回的是一个字符串,而且内容是xml格式的,结果在解析json的时候报错,最终修改了接口的返回方式,以Map返回, 才得以接收到这个xml的字符串,然后通过dom4j ...

  7. CF 586A 找1的个数和101的个数

    Sample test(s) input 50 1 0 1 1 output 4 input 71 0 1 0 0 1 0 output 4 input 10 output 0 # include & ...

  8. day1作业:登录接口

    作业一:编写登陆接口 1.输入用户名和密码 2.认证成功后显示欢迎信息 3.输错三次后锁定 思路: (1)用户输入用户名: (2)去锁定文件中验证用户名是否锁定: (3)去当前用户验证用户是否存在: ...

  9. PHP随机浮点数

    function randomFloat($min = 0, $max = 1) { $rand = mt_rand(); $lmax = mt_getrandmax(); return $min + ...

  10. Zookeeper服务器集群的搭建与操作

    ZooKeeper 作用:Zookeeper 可以用来保证数据在zk集群之间的数据的事务性一致(原子操作). 介绍:Zookeeper 是 Google 的 Chubby一个开源的实现,是 Hadoo ...