打表找规律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时 ...
随机推荐
- 【vue】index.html main.js app.vue index.js怎么结合的? 怎么打包的?搜集的信息
转载:https://blog.csdn.net/yudiandemingzi/article/details/80247137 怎么结合的: 一.启动项目 第一步:cmd进入项目文件里,运行npm ...
- 【转】Apache httpd.conf配置解释
转自:http://jafy00.blog.51cto.com/2594646/501373 常用配置指令说明 1. ServerRoot:服务器的基础目录,一般来说它将包含conf/和logs/子目 ...
- PHP面向对象之抽象类,抽象方法
抽象类,抽象方法 抽象类: 是一个不能实例化的类: 定义形式: abstract class 类名{} 为什么需要抽象类: 它是为了技术管理而设计! 抽象方法: 是一个只有方法头,没有方法体的方法 ...
- 【C++】为多态基类声明virtual析构函数
来自<Effective C++>条款07:为多态声明virtual析构函数 当derived class对象经由一个base class指针被删除,而该base class带着一个non ...
- HDU4701_Game
很有意思,很好的一个题目. 题目的意思是两个人初始状态分别有A和B元,现在有N件可买的商品.两人轮流买,商品必须从左到右买过去,一次可以买若干个.第一个无法买到商品的人输. 一看就知道是博弈题目,但是 ...
- 后缀树的线性在线构建-Ukkonen算法
Ukkonen算法是一个非常直观的算法,其思想精妙之处在于不断加字符的过程中,用字符串上的一段区间来表示一条边,并且自动扩展,在需要的时候把边分裂.使用这个算法的好处在于它非常好写,代码很短,并且它是 ...
- Proving Equivalences UVALive - 4287(强连通分量 水题)
就是统计入度为0 的点 和 出度为0 的点 输出 大的那一个,, 若图中只有一个强连通分量 则输出0即可 和https://www.cnblogs.com/WTSRUVF/p/9301096.htm ...
- Zabbix概术及基础介绍(一)
一.Zabbix介绍 Zabbix 是由Alexei Vladishev创建,目前由Zabbix SIA在持续开发和支持.Zabbix 是一个企业级的分布式开源监控方案.Zabbix是一款能够监控各种 ...
- linux内核分析 第三周 构造一个简单的Linux系统MenuOS
一.计算机的三个法宝 存储程序计算机,函数调用堆栈,中断二.操作系统的两把剑:1.中断上下文的切换,保存现场和恢复现场2.进程上下文的切换. 三.linux内核源代码的分析: ·arch/目录保存支持 ...
- [ACM][2018南京预赛]Lpl and Energy-saving Lamps
一.题面 样例输入: 5 4 3 10 5 2 7 10 5 1 4 8 7 2 3 6 4 7 样例输出: 4 0 1 1 3 6 5 1 5 1 2 0 3 2 4 4 3 6 5 1 二.思路 ...