Contest - 多校训练(985专场) Problem C: 985的方格难题
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1157&pid=2
Description
Input
Output
Sample Input Sample Output -
分析:组合数/dp
dp:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include <iostream>
#include<algorithm>
#include<queue>
#define N 100
using namespace std; int main()
{
int T,i,n,j,dp[N][N],x,y; scanf("%d", &T); while(T--)
{
scanf("%d %d %d", &n,&x,&y);
memset(dp,,sizeof(dp)); for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
if(i==x&&j==y)///
dp[i][j]=;
else if(i==&&j==)///
dp[i][j]=;///1和2顺序反了,wa~wa~wa~
else
dp[i][j]=dp[i-][j]+dp[i][j-]; dp[i][j]%=;
} if(dp[n][n]==)
printf("-1\n");
else
printf("%d\n", dp[n][n]);
}
return ;
}
组合数:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include <iostream>
#include<algorithm>
#include<queue>
#define N 10005
using namespace std; long long c(long long n,long long m)
{
if(m > n/)
m = n-m;
long long a =, b =;
for(int i =; i <= m; i++)
{
a *= n-i+;
b *= i;
if(a % b ==)
{
a /= b;
b =;
}
}
return a/b;
}
int main()
{
int t, n, x, y;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &n, &x, &y);
if((x == && y == )||(x == n && y == n))
{
printf("-1\n");
continue;
}
else
{
long long a = c(n*-, n-);
long long b = c(n*-x-y, n-x) * c( x+y--, x-);
int ans = (a-b)%;
printf("%d\n", ans);
}
}
return ;
}
Contest - 多校训练(985专场) Problem C: 985的方格难题的更多相关文章
- 算法训练 A+B Problem
算法训练 A+B Problem 时间限制:1.0s 内存限制:512.0MB 问题描述 输入A,B. 输出A+B. 输入格式 输入包含两个整数A,B,用一个空格分隔. 输出格式 ...
- 2019 Multi-University Training Contest 2: 1010 Just Skip The Problem 自闭记
2019 Multi-University Training Contest 2: 1010 Just Skip The Problem 自闭记 题意 多测.每次给你一个数\(n\),你可以同时问无数 ...
- HDU6578 2019HDU多校训练赛第一场 1001 (dp)
HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...
- HDU6579 2019HDU多校训练赛第一场1002 (线性基)
HDU6579 2019HDU多校训练赛第一场1002 (线性基) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题意: 两种操作 1.在序列末 ...
- HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分)
HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分) 传送门:http://acm.hdu.edu.cn/showproblem.php? ...
- Problem H: 小火山的围棋梦想 多校训练2(小火山专场)
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1908 题意:如果'.'被'*'围起来,就把'.'变为'*'. 分析:如果是'*'直接输出, ...
- Problem A: 小火山的跳子游戏 多校训练2(小火山专场)(周期)
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1158&pid=0 zzuli 1905 题意:如果k=1的话是1,2,3,4. ...
- 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D】---暑假三校训练
2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D Problem D. Distribution in Metagonia Input ...
- 【2016多校训练4】Multi-University Training Contest 4
1001 Another Meaning 题意:字符串A中包含的字符串B可以翻译或不翻译,总共有多少方案. 题解:动规,dp[i]表示A的第i位为止有多少方案. 转移方程: dp[i]=dp[i-1 ...
随机推荐
- B - ACboy needs your help(动态规划,分组背包)
B - ACboy needs your help Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- BJFU 1397 致我们终将逝去的爱情
LIS 由于要记录轨迹,所以不能用O(nlogn)优化,直接dp加father记录每个节点的转移. #include<cstdio> #include<algorithm> ...
- xtrabackup 2.0.8备份mysql5.1.65报错
sh : xtrabackup not found innobackupex: fatal error: no 'mysqld' group in MySQL options fix: add inn ...
- 运行指定路径下的exe
public void StartProcess(string name) { string exeFileName = "DataControl.exe"; string sta ...
- 3.Perl 多线程:Threads(exit thread_only)
还可以在导入threads模块时设置: use threads ('exit' => 'thread_only');
- SQL Server删除表信息的三种方法
1.使用DELETE实现SQL Server删除表信息 (1)删除表中的全部信息 USE student GO DELETE student --不加where条件,删除表中的所有记录 go ...
- drawableLayout的使用(转载讲的比较清晰的文章)
创建drawbler的布局文件 初始化drawbler的列表 响应drawable列表点击事件 现在侧滑菜单使用很多,大都是通过SlidingMenu实现.现在也可以通过DrawerLayout 创建 ...
- 4-static(静态变量)关键字
1.使用static声明属性 static声明全局属性2.使用static声明方法 直接通过类名调用3.注意点 使用static方法的时候,只能访问static声明的属性和方法,而非static声明的 ...
- ASP.NET MVC 使用带有短横线的html Attributes
我们常常需要一个文本框来输入用户名,在asp.net mvc 中可以使用 TextBoxFor.有时候我们想为这个文本框添加一些特性,比如 html5 的data-,如果直接写data-是会提示错误的 ...
- Linux平台从文件中查找字符赋值于变量
以telnet方式登录Linux主机,在默认目录下用命令创建一个包含DUT wanIP的文本文件.[root] echo wanIP=88.0.100.253 > ./wanIP.txt在默认目 ...