CodeForces 630 I. Parking Lot(组合数学)
来源:互联网 发布:张宴 nginx 编辑:程序博客网 时间:2024/05/15 10:51
Description
一公司奖励员工4种不同的汽车,每种汽车完全相同,而公司的停车场只有2n-2个停车位,所以停车场停不下所有车,甚至连一种车都停不完,而老板觉得如果停车场恰有n辆相同的车排在一起会很好看,问有多少种停车方案
Input
一个整数n(3<=n<=30)
Output
停车方案数
Sample Input
3
Sample Output
24
Solution
简单组合,如果这n辆车在停车场两端,那么停车方案数为4 * 3 * 4 ^ (n-3),如果这n辆车不在两端,那么停车方案为4 * (n-3) * 3 * 3 * 4 ^ (n-4),故ans=24 * 4 ^ (n-3)+36 * (n-3) * 4 ^ (n-4)
Code
#include<cstdio>#include<iostream>using namespace std;typedef long long ll;int n;ll mod_pow(ll a,int b){ if(b<0)return 1; ll ans=1ll; while(b) { if(b&1)ans=ans*a; a=a*a; b>>=1; } return ans;}int main(){ while(~scanf("%d",&n)) { ll ans=24*mod_pow(4ll,n-3)+36*(n-3)*mod_pow(4ll,n-4); printf("%I64d\n",ans); } return 0;}
0 0
- CodeForces 630 I. Parking Lot(组合数学)
- codeforces 630 I Parking Lot (规律&&组合)
- CodeForces - 630I Parking Lot (数学排列组合)
- Codeforces--630I--Parking Lot(规律)
- codeforces 630I Parking Lot
- Codeforces 630I Parking Lot
- codeforces #630 I. Parking Lot
- CodeForces-630 I. Parking Lot【排列组合】
- CodeForces 630I:Parking Lot【排列组合】
- Codeforces-46D Parking Lot
- 【codeforces】480E Parking Lot
- Codeforces 46D Parking Lot(贪心模拟)
- CodeForces 46D Parking Lot(线段树区间合并)
- codeforces 46D Parking Lot(线段树 区间合并)
- Codeforces Beta Round #43 D. Parking Lot
- Codeforces Beta Round #43 D. Parking Lot
- Codeforces 46D Parking Lot(线段树)
- Codeforces 46D Parking Lot 枚举
- linux yum命令详解
- Flash Media Server 优化指南
- CBLAS的安装与使用
- android MulticastLock
- apriori和关联规则算法
- CodeForces 630 I. Parking Lot(组合数学)
- [自考]计算机网络原理
- 程序员面试笔试宝典学习记录(一)(常见面试笔试题目)
- hdu 1151 Air Raid(最小路径覆盖)
- [BZOJ 4066]简单题
- npm package.json字段简介
- 三维偏序 CDQ
- 《数据结构与算法分析(c 描述)》—— 第四章笔记
- HBitmap、Bitmap、CBitmap之间的区别与联系