打表找规律C - Insertion Sort Gym - 101955C
题目链接:https://cn.vjudge.net/contest/273377#problem/C
给你 n,m,k.
这个题的意思是给你n个数,在对前m项的基础上排序的情况下,问你满足递增子序列的长度至少为n-1的排列组合的个数。
具体方法:打表找规律。
打表代码:
#include<bits/stdc++.h>
#include<string>
#include<cstring>
#include<stdio.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn =1000;
int a[maxn];
int vis[maxn];
int ww[maxn][maxn];
int b[maxn];
bool judge(int t,int w)
{
for(int i=1; i<=t; i++)
{
b[i]=a[i];
}
sort(b+1,b+w+1);
memset(vis,0,sizeof(vis));
int ans=0;
int temp;
for(int i=t; i>=1; i--)
{
temp=1;
int maxx=0;
for(int j=i; j<=t; j++)
{
if(b[j]>b[i])
{
maxx=max(maxx,vis[j]);
}
}
vis[i]=maxx+1;
}
for(int i=1; i<=t; i++)
{
if(vis[i]>=t-1)return true;
}
return false;
}
int main()
{
int t=10;
while(1)
{
if(t==0)break;
for(int i=1; i<=t; i++)
{
a[i]=i;
}
do
{
// cout<<t<<endl;
for(int i=1; i<=t; i++)
{
if(judge(t,i))
{
ww[t][i]++;
}
}
// for(int i=0;i<t;i++)
// cout<<a[i]<<" ";
// cout<<endl;
} while(next_permutation(a+1,a+t+1));
t--;
}
for(int i=1; i<=10; i++)
{
for(int j=1; j<=i; j++)
{
cout<<ww[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
/*
1
2 2
5 6 6
10 14 24 24
17 26 54 120 120
26 42 96 264 720 720
37 62 150 456 1560 5040 5040
50 86 216 696 2640 10800 40320 40320
65 114 294 984 3960 18000 85680 362880 362880
82 146 384 1320 5520 26640 141120 766080 3628800 3628800
*/
AC代码:
#include<bits/stdc++.h>
#include<string>
#include<cstring>
#include<stdio.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn =60;
ll dp[maxn][maxn];
ll a[maxn];
ll n,m,k;
void init()
{
a[1]=2;
for(int i=2; i<=50; i++)
{
a[i]=(a[i-1]*i)%k;
}
dp[1][1]=1;
if(m>n)m=n;
for(int i=2; i<=50; i++)
{
dp[i][i]=dp[i][i-1]=(dp[i-1][i-1]*i)%k;
}
for(int i=m+2; i<=50; i++)
{
dp[i][m]=(dp[i-1][m]*2-dp[i-2][m]+a[m]+k)%k;//这里需要加k,因为有可能出现负值
}
}
int main()
{
int T;
scanf("%d",&T);
int Case=0;
while(T--)
{
scanf("%lld%lld%lld",&n,&m,&k);
init();
printf("Case #%d: ",++Case);
printf("%lld\n",dp[n][m]);
}
return 0;
}
打表找规律C - Insertion Sort Gym - 101955C的更多相关文章
- Insertion Sort Gym - 101955C 思路+推公式
题目:题目链接 题意:对长为n的1到n的数列的前k个数排序后数列的最长上升子序列长度不小于n-1的数列的种数,训练赛时怎么都读不明白这个题意,最后还是赛后问了旁队才算看懂,英语水平急需拯救55555 ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu_5894_hannnnah_j’s Biological Test(打表找规律)
题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
随机推荐
- java 基础 --final--008
finally:被finally控制的语句一定会执行,但是如果执行之前jvm退出了,就不会执行了.比如System.exit(0);final:常见的可以修饰类(该类不能被继承) 方法(方法不能被重写 ...
- 虚拟机中安装 centOS,本地安装 SSH 连接 - 01
下面把自己安装 centOS 的过程记录下,选取的版本是 centOS6.8 ,下载地址在脚本之家 down 的 : 阿里云 x64 http://mirrors.aliyun.com/centos/ ...
- Spring异步事件
1.发布事件 @Data public class CustomEvent extends ApplicationEvent implements Serializable { private Boo ...
- Centos7安装完毕后联网-设置ip地址(VMware虚拟机)
VMware虚拟机中安装了Centos7,为了让Centos能够访问外网及设置固定的ip地址以方便本地通过SSH访问Centos,做以下几步.本文来自osfipin note. 1.确认虚拟机网络链接 ...
- C++解析(1):C到C++的升级
0.目录 1.C与C++的关系 2.C到C++的升级 2.1 语言的实用性 2.2 register关键字 2.3 同名的全局变量 2.4 struct关键字 2.5 int f() 与 int f( ...
- ADM pro破解百度云限速 ADM pro设置方法 ES文件管理器
ADM Pro打开ADM,[设置]–>[下载]–>[找下面的选项]:1.[User-Agent] –>选择[Custom]2.[Custom User-Agent]3.填写:netd ...
- PD模型创建完获取生成表脚本
1.双击表名,弹出属性对话框-->General----> Owner 表名前缀,如XX.SYS_TABLE 最好去掉 2.Preview 复制里面的脚本到数据库执行下即可
- CF712E Memory and Casinos 期望概率
题意:\(n\)个赌场,每个赌场有\(p_{i}\)的胜率,如果赢了就走到下一个赌场,输了就退回上一个赌场,规定\(1\)号赌场的上一个是\(0\)号赌场,\(n\)号赌场的下一个是\(n + 1\) ...
- 【移动支付】.NET微信扫码支付接入(模式二-NATIVE)
一.前言 经过两三天的琢磨总算完成了微信扫码支付功能,不得不感叹几句: 微信提供的DEMO不错,直接复制粘贴就可以跑起来了: 微信的配置平台我真是服了.公众平台.商户平台.开放平台,一个平 ...
- windows主机防护
Netsh命令-修改网络IP设置 网络管理相关函数 Windows用户相关操作 SID(安全标识符) 策略其他说明 主机防护设置 命令行添加防火墙 防火墙规则 使用SetupDI* API列举系统中的 ...