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 ...
随机推荐
- UGUI学习笔记
基本情况:熟悉NGUI 没接触过UGUI 目标:熟练掌握UGUI,并用在实际项目中 一 在网上寻找视频教程,快速了解UGUI http://www.taikr.com/course/89 不错的视频 ...
- Zookeeper 启动错误
启动后日志如下 : 2016-09-14 05:51:19,449 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeade ...
- 封装一个Ajax工具函数
/*封装一个ajax工具函数*/ window.$ = {}; /*通过$定义一个ajax函数*/ /* * 1. type string 请求的方式 默认是get * 2. url ...
- html5学习(二)音频audio
音频格式 当前,audio 元素支持三种音频格式: IE 9 Firefox 3.5 Opera 10.5 Chrome 3.0 Safari 3.0 Ogg Vorbis √ √ √ M ...
- ZOJ 1967 POJ 2570 Fiber Network
枚举起点和公司,每次用DFS跑一遍图,预处理出所有的答案.询问的时候很快就能得到答案. #include<cstdio> #include<cmath> #include< ...
- VBS 自动发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- Java-多重if 结构
import java.util.*;public class ifs { public static void main(String args[]){ Scanner in=new Scanner ...
- Mac Git 学习笔记
lapommedeMacBook-Pro:~ lapomme$ cd GitHub lapommedeMacBook-Pro:GitHub lapomme$ cd lapommedeMacBook-P ...
- ios导航栏适配
我们做屏幕导航栏横竖屏适配的时候,会发现top的值多少都有一点的偏移,加了背景色之后从0开始,不加背景色从64开始,解决方法self.extendedLayoutIncludesOpaqueBars ...
- listview解决滑动条目的时候背景变为黑色的问题
方式一:java代码: listView.setCacheColorHint(0); 方式二:布局文件 <ListView android:id="@+id/listView1&quo ...