ZOJ 1202 Divide and Count(排列组合)
and count zoj 排列组合
2023-09-14 08:58:22 时间
Divide and Count
题目大意:给定箱子的数量和每个箱子的容量,在每个箱子里都装满对应容量的宝石,每颗宝石都是独一无二的,求一共有多少种放置方式。但是如果两个箱子的容量相同,则认为是 同一种箱子
Sample input:
2 3 3 3 1 2 3
Sample output:
10 60
分析:这是练习赛的时候处在HUST上的题目,当时感觉代码完全对了,却坑了半天,看了题解才发现,是最后除以相同的箱子的时候,是除以它的数量的阶乘,本来是这么想的,却先把它们给乘起来了,样例只是碰巧对而已。也用不到64位整数。
代码如下:
1 #include <iostream> 2 # include<cstdio> 3 # include<cstring> 4 using namespace std; 5 6 int f(int a,int b) //从a到b的乘积 7 { 8 int i; 9 int ans= 1; 10 for(i=a; i<=b; i++) 11 { 12 ans *= i; 13 } 14 return ans; 15 } 16 int main() 17 { 18 int i,T,sum,hh,ans; 19 int num[13],a[13]; 20 while(scanf("%d",&T)!=EOF) 21 { 22 23 sum = 0; 24 for(i=0; i<=12; i++) 25 a[i]=0; 26 for(i=0; i<T; i++) 27 { 28 scanf("%d",&num[i]); 29 a[num[i]]++; 30 sum += num[i]; 31 } 32 ans =1; 33 for(i=0; i<T; i++) 34 { 35 ans *= f(sum-num[i]+1,sum)/f(1,num[i]); 36 sum -= num[i]; 37 } 38 for(i=0; i<=12; i++) 39 { 40 if(a[i]>1) 41 ans /= f(1,a[i]); //这里除以阶乘 42 } 43 printf("%d\n",ans); 44 } 45 return 0; 46 }
相关文章
- ORA-02166: ARCHIVELOG and NOARCHIVELOG specified ORACLE 报错 故障修复 远程处理
- ORA-27049: unable to seek to and read the last block ORACLE 报错 故障修复 远程处理
- ORA-38475: The attribute set and the associated ADT are out of sync. ORACLE 报错 故障修复 远程处理
- ORA-39926: Join index between table string.string in tablespace string and table string.string in tablespace string. ORACLE 报错 故障修复 远程处理
- ORA-39934: Materialized view log string.string in tablespace string and master table string.string in tablespace string are not fully contained in the transportable set. ORACLE 报错 故障修复 远程处理
- ORA-47027: Factor Link does not exist for string and string ORACLE 报错 故障修复 远程处理
- 用法研究Oracle中的COUNT函数用法(Oracle中count)
- Exploring the Power and Capabilities of the Linux eCos Operating System(linuxecos)
- Exploring the Powerful Combination of Linux and FPGA for HighPerformance Computing(linuxfpga)
- Exploring the Ethernet Interface eth3 on Linux for Networking and Connectivity(linuxeth3)
- Exploring Redis: Understanding and Managing Current Connection Count(redis当前连接数)
- Managing Your MySQL Database Files: Tips and Tricks for Efficient Data Storage(mysql数据库文件)
- How to Use Oracle for Smoother PPT Presentations: Top Tips and Tricks(pptoracle)
- Exploring the Versatile World of Linux PDA: Features Applications and Advantages(linuxpda)
- Exploring the Power and Functionality of Oracle OC4J for Efficient Web Development(oracleoc4j)
- 深入理解MySQL中的Count函数应用及其用途(mysql 中count)
- MySQL中AND的使用方法解析(mysql中and的用法)
- MySQL中的AND和OR使用逻辑运算符优化查询语句(mysql中and与or)