• hust 1413 Permutation Design


    题目描述

           xiaoY is crazy about solving equations! But since teacher HH tells him that when an equation’s degree is bigger than 3, there are no analytic solutions, so he feels very upset! With a few days of trial, he truly trusts his teacher’s words and he focuses on another interesting problem. What is the “Permutation function group” like!

           A “Permutation function group” means the coefficient of the function is a permutation of 1 ~N and the format is

            F(x) = a1*x^ (1^3) + a2*x^ (2^3) … + an*x^ (N^3);

    He is interested about what the F(x) is like when a1...aN form the Kth permutation of all;

    As you see, when N=4:

           S (1):    1 2 3 4

           S (2):     1 2 4 3

           S (3):     1 3 2 4

           …

          S (N)      4 3 2 1

    Now give you N, k and x, you just need to tell xiaoY F(x) mod 1000000007 (in case F(x) too large! We module 1000000007)

    输入

    Multiple cases.

    N, K, X (0<N<=1000, 0<K<=3000, x<10^9)

    0 0 0 indicates the end of input!

    输出

    F(x) mod 1000000007

    样例输入

    2 2 2
    0 0 0
    

    样例输出

    260
    

    提示

    2 * 2^(1^3) + 1 * 2^(2^3) = 4 + 256 = 260

    这个题考了两个知识点

    1,怎么求下一个排列

    2,当然是快速幂了

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<string>
    using namespace std;
    
    const long long mod=1000000007;
    long long a[1001];
    void init()
    {
        for (long long i=1;i<=1000;i++)
        a[i]=i*i*i;
    }
    
    int f[1001];
    
    long long find(long long n,long long x)
    {
        long long e=1,tmp=x;
        while(n)
        {
            if (n & 1)
            e=(e*tmp)%mod;
            tmp=(tmp*tmp)%mod;
            n >>=1;
        }
        return e%mod;
    }
    
    int main()
    {
        init();
        long long n,k,x,ans;
        while (scanf("%lld%lld%lld",&n,&k,&x)!=EOF && !(x==0 && n==0 && k==0))
        {
            for (int i=1;i<=n;i++) f[i]=i;
            k--;
            while(k--)
            {
                int m=next_permutation(f+1,f+n+1);
            }
            ans=0;
            for (int i=1;i<=n;i++)
            {
                ans+=(f[i]*find(a[i],x))%mod;
            }
            printf("%lld
    ",ans%mod);
        }
        return 0;
    }
    至少做到我努力了
  • 相关阅读:
    巧用自定义注解,一行代码搞定审计日志
    手把手教你写一个SpringMVC框架
    SpringBoot 实现 excel 全自由导入导出,性能强的离谱,用起来还特优雅
    vite+vue3+typescript的env变量使用方法
    数组的基本定义方法
    oracle virtualBox与windows 10 wsl2兼容配置解决
    本地镜像push到dockerHub
    virtualbox安装centOS7 报错 not syncing fatal exception
    docker 常用指令
    Linux安装常用
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3734243.html
Copyright © 2020-2023  润新知