light oj 1005 不知道是个什么玩意
来源:互联网 发布:淘宝武汉飞鱼运动 编辑:程序博客网 时间:2024/05/01 16:31
A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizontally from its current position and two rooks attack each other if one is on the path of the other. In the following figure, the dark squares represent the reachable locations for rook R1 from its current position. The figure also shows that the rook R1 and R2 are in attacking positions where R1 and R3 are not. R2 and R3 are also in non-attacking positions.
Now, given two numbers n and k, your job is to determine the number of ways one can put k rooks on an n x n chessboard so that no two of them are in attacking positions.
Input
Input starts with an integer T (≤ 350), denoting the number of test cases.
Each case contains two integers n (1 ≤ n ≤ 30) and k (0 ≤ k ≤ n2).
Output
For each case, print the case number and total number of ways one can put the given number of rooks on a chessboard of the given size so that no two of them are in attacking positions. You may safely assume that this number will be less than 1017.
Sample Input
Output for Sample Input
8
1 1
2 1
3 1
4 1
4 2
4 3
4 4
4 5
Case 1: 1
Case 2: 4
Case 3: 9
Case 4: 16
Case 5: 72
Case 6: 96
Case 7: 24
Case 8: 0
这题我真的不知道是个什么…
也许是个数学题
但是归类非说是DP…
鬼知道是什么玩意
反正状态转移一晚上没找到….
GTMDDP!!
思路是这样的…
你第一个可以随便选…
有n^2个..第二次就只有(n-1)^2个了…
以此类推…..
但是你这个第一个和第X个也许…会放重复
但你多算了…
因此除以k的全排列就可以….
这怎么可能是DP.嗯?!!
这怎么转移?!!
#include <iostream>#include<cstdio>#include<vector>#include<algorithm>#include<cmath>#include<memory.h>using namespace std;long long x[31];int biaoji[31];int main(){ for(int a=1;a<=30;a++)x[a]=a*a; int T; cin>>T; int u=0; while(T--) { int n,k; cin>>n>>k; if(k>n) { printf("Case %d: 0\n",++u); continue; } long long sum=1; memset(biaoji,0,sizeof(biaoji)); for(int a=n-k+1;a<=n;a++) { sum*=x[a]; for(int b=1;b<=k;b++) { if(biaoji[b]==0) { if(sum%b==0) { biaoji[b]=1; sum/=b; } } } } printf("Case %d: %lld\n",++u,sum); } return 0;}
- light oj 1005 不知道是个什么玩意
- IT是个什么玩意
- IT是个什么玩意
- cache是个什么玩意
- NuGet 是个什么玩意?
- NuGet是个什么玩意
- NuGet 是个什么玩意?
- Maven是个什么玩意
- 债券是个什么玩意
- raspberry是个什么玩意
- 信用是个什么玩意
- locale到底是个什么玩意
- 用户是个什么玩意(1)
- 互联网思维是个什么玩意
- HoneyDrive 到底是个什么玩意
- H5到底是个什么玩意?!
- 您所不知道的15个USB小玩意
- Oxite是个什么玩意-Oxite基本概念和配置
- sqllite (3) - c# .net 使用 dapper 操作 sqllite 数据库
- zookeeper的完全分布式安装
- Thread.setDaemon说明
- Mysql事物处理
- Xenserver6.2设置VM开机自动启动
- light oj 1005 不知道是个什么玩意
- find & grep 结合查找 某字符串 所在文件
- sim卡姓名长度最大为14字节可以输入11个相同汉字
- IT-linux-cgroups
- JSON中换行符的处理
- Myeclipse
- NGUI所见即所得之UITweener
- Android异步处理之AsyncTask
- Swift整形