zoukankan      html  css  js  c++  java
  • 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;
    }
    至少做到我努力了
  • 相关阅读:
    xml
    反射
    类加载器
    tcp通信
    UDP通信
    UDP与TCP协议
    网络通信协议
    符合汽车安全和质量标准的CYPRESS FRAM
    SRAM是什么存储器
    网络通信与便携式应用驱动SRAM技术发展
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3734243.html
Copyright © 2011-2022 走看看