题目链接: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的更多相关文章

  1. Insertion Sort Gym - 101955C 思路+推公式

    题目:题目链接 题意:对长为n的1到n的数列的前k个数排序后数列的最长上升子序列长度不小于n-1的数列的种数,训练赛时怎么都读不明白这个题意,最后还是赛后问了旁队才算看懂,英语水平急需拯救55555 ...

  2. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  3. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  4. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  5. 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 ...

  6. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  7. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  8. hdu_5894_hannnnah_j’s Biological Test(打表找规律)

    题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...

  9. hdu_5795_A Simple Nim(打表找规律的博弈)

    题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...

随机推荐

  1. babel-preset-env: a preset that configures Babel for you

    转载 babel-preset-env is a new preset that lets you specify an environment and automatically enables t ...

  2. SQL Inserted和deleted详解

    create trigger updateDeleteTime on user for update as begin update user set UpdateTime=(getdate()) f ...

  3. 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek

    题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...

  4. C++四种类型转化

    2018-08-02 (星期四)C++类型转换:static_cast提供编译时期静态类型检测:    static_cast <type-id> (expression)    1)完成 ...

  5. 【NuGet】使用NuGet打包并发布至ProGet过程 (打包再次详解)【下篇】

    一.前言 上篇[1]主要介绍了利用csproj文件使用NuGet打包至ProGet的过程,并附上了用于在Jenkins上运行的python脚本.本篇的主要内容分为以下几点: 1. Nuspec与Nup ...

  6. 【HDU5730】Shell Necklace(多项式运算,分治FFT)

    [HDU5730]Shell Necklace(多项式运算,分治FFT) 题面 Vjudge 翻译: 有一个长度为\(n\)的序列 已知给连续的长度为\(i\)的序列装饰的方案数为\(a[i]\) 求 ...

  7. 解决:warning LNK4098: 默认库“MSVCRT”与其他库的使用冲突;找到 MSIL .netmodule 或使用 /GL 编译的模块;正在。。;LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/LTCG”规范)

    原文链接地址:https://www.cnblogs.com/qrlozte/p/4844411.html 参考资料: http://blog.csdn.net/laogaoav/article/de ...

  8. Linux基础-配置网络、集群内主机名设定、ssh登入、bash命令、通配符(元字符)

    作业一:临时配置网络(ip,网关,dns)+永久配置 设置临时网络配置: 配置IP ifcongfig ens33 192.168.16.177/24 (ifconfig 网卡 ip地址    /24 ...

  9. Git入门指南

    git学习资源: Pro Git(中文版) Learn Git in your browser for free with Try Git. Git常用命令 Reference 常用 Git 命令清单 ...

  10. WinForm二三事(三)Control.Invoke&Control.BeginInvoke

    http://www.cnblogs.com/yuyijq/archive/2010/01/11/1643802.html 这个系列从2009年写到2010年,差点又成太监文.随着WPF/Silver ...