hdu 3811 Permutation

Problem Description
In combinatorics a permutation of a set S with N elements is a listing of the elements of S in some order (each element occurring exactly once). There are N! permutations of a set which has N elements. For example, there are six permutations of the set {1,2,3}, namely [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
But Bob think that some permutations are more beautiful than others. Bob write some pairs of integers(Ai, Bi) to distinguish beautiful permutations from ordinary ones. A permutation is considered beautiful if and only if for some i the Ai-th element of it is Bi. We want to know how many permutations of set {1, 2, ...., N} are beautiful.
 

Input
The first line contains an integer T indicating the number of test cases.
There are two integers N and M in the first line of each test case. M lines follow, the i-th line contains two integers Ai and Bi.

Technical Specification
1. 1 <= T <= 50
2. 1 <= N <= 17
3. 1 <= M <= N*N
4. 1 <= Ai, Bi <= N
 

Output
For each test case, output the case number first. Then output the number of beautiful permutations in a line.
 

Sample Input
  
3 3 2 1 1 2 1 3 2 1 1 2 2 4 3 1 1 1 2 1 3
 

Sample Output
  
Case 1: 4 Case 2: 3 Case 3: 18
 

Author
hanshuai
 

Source


又是一题状态dp……当年比赛的时候RE到死没出来,今天1Y……rp咩?

#include <stdio.h>
#include <string.h>

int map[20][20];
long long dp[1<<18];
long long fact[18];

int main()
{
    int i,j,n,T,m,x,y,p,k,cnt;
    scanf("%d",&T);
    fact[0]=1;
    for (i=1;i<18;i++)
    {
        fact[i]=fact[i-1]*i;
    }
    cnt=1;
    while(T--)
    {
        scanf("%d%d",&n,&m);
        memset(map,0,sizeof(map));
        for (i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            x--;
            y--;
            map[x][y]=1;
        }
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        for (i=0;i<n;i++)
        {
            for (j=(1<<n)-1;j>=0;j--)
            {
                if (dp[j]==0) continue;
                for (k=0;k<n;k++)
                {
                    if ((j & (1<<k))!=0) continue;
                    if (map[i][k]==1) continue;
                    p=(j | (1<<k));
                    dp[p]+=dp[j];
                }
            }
        }
        printf("Case %d: %I64d\n",cnt++,fact[n]-dp[(1<<n)-1]);
    }
    return 0;
}


源码地址: https://pan.quark.cn/s/3916362e5d0a 在C#编程平台下,构建一个曲线编辑器是一项融合了图形用户界面(GUI)构建、数据管理及数学运算的应用开发任务。 接下来将系统性地介绍这个曲线编辑器开发过程中的核心知识点:1. **定制曲线面板展示数据曲线**: - 控件选用:在C#的Windows Forms或WPF框架中,有多种控件可用于曲线呈现,例如PictureBox或用户自定义的UserControl。 通过处理重绘事件,借助Graphics对象执行绘图动作,如运用DrawCurve方法。 - 数据图形化:通过线性或贝塞尔曲线连接数据点,以呈现数据演变态势。 这要求掌握直线与曲线的数学描述,例如两点间的直线公式、三次贝塞尔曲线等。 - 坐标系统与缩放比例:构建X轴和Y轴,设定坐标标记,并开发缩放功能,使用户可察看不同区间内的数据。 2. **在时间轴上配置多个关键帧数据**: - 时间轴构建:开发一个时间轴组件,显示时间单位刻度,并允许用户在特定时间点设置关键帧。 时间可表现为连续形式或离散形式,关键帧对应于时间轴上的标识。 - 关键帧维护:利用数据结构(例如List或Dictionary)保存关键帧,涵盖时间戳和关联值。 需考虑关键帧的添加、移除及调整位置功能。 3. **调整关键帧数据,通过插值方法获得曲线**: - 插值方法:依据关键帧信息,选用插值方法(如线性插值、样条插值,特别是Catmull-Rom样条)生成平滑曲线。 这涉及数学运算,确保曲线在关键帧之间无缝衔接。 - 即时反馈:在编辑关键帧时,即时刷新曲线显示,优化用户体验。 4. **曲线数据的输出**: - 文件类型:挑选适宜的文件格式存储数据,例如XML、JSON或...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值