• bzoj1025


    想到是lcm 但是没有想到这么奇怪的背包dp。。。

    题解跪lsj

     1 #include<bits/stdc++.h>
     2 #define lowbit(a) ((a)&(-(a)))
     3 #define clr(a,x) memset(a,x,sizeof(a))
     4 #define rep(i,l,r) for(int i=l;i<(r);i++)
     5 typedef long long ll;
     6 using namespace std;
     7 int read()
     8 {
     9     char c=getchar();
    10     int ans=0,f=1;
    11     while(!isdigit(c)){
    12         if(c=='-') f=-1;
    13         c=getchar();
    14     }
    15     while(isdigit(c)){
    16         ans=ans*10+c-'0';
    17         c=getchar();
    18     }
    19     return ans*f;
    20 }
    21 const int maxn=1009,maxp=100000;
    22 int n,cnt=1,p[maxp];
    23 ll d[maxn][maxn];
    24 bool isp[maxp];
    25 void get_prime(){
    26     clr(isp,-1);
    27     rep(i,2,n+1){
    28         if(isp[i]) p[cnt++]=i;
    29         rep(j,1,cnt){
    30             if(i*p[j]>n) break;
    31             isp[i*p[j]]=0;
    32             if(i%p[j]==0) break;
    33         }
    34     }
    35 }
    36 void solve(){
    37     d[0][0]=1;
    38     rep(i,1,cnt){
    39         rep(j,0,n+1){
    40             d[i][j]=d[i-1][j];
    41             int t=1;
    42             rep(k,0,n){
    43                 t*=p[i];
    44                 if(t>j) break;
    45                 d[i][j]+=d[i-1][j-t];
    46             }
    47         }
    48     }
    49     ll ans=0;
    50     rep(i,0,n+1) ans+=d[cnt-1][i];
    51     cout<<ans;
    52 }
    53 int main()
    54 {    
    55     n=read();
    56     get_prime();
    57     solve();
    58     return 0;
    59 }
    View Code

    1025: [SCOI2009]游戏

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 1561  Solved: 979
    [Submit][Status][Discuss]

    Description

    windy学会了一种游戏。对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应。最开始windy把数字按顺序1,2,3,……,N写一排在纸上。然后再在这一排下面写上它们对应的数字。然后又在新的一排下面写上它们对应的数字。如此反复,直到序列再次变为1,2,3,……,N。 如: 1 2 3 4 5 6 对应的关系为 1->2 2->3 3->1 4->5 5->4 6->6 windy的操作如下 1 2 3 4 5 6 2 3 1 5 4 6 3 1 2 4 5 6 1 2 3 5 4 6 2 3 1 4 5 6 3 1 2 5 4 6 1 2 3 4 5 6 这时,我们就有若干排1到N的排列,上例中有7排。现在windy想知道,对于所有可能的对应关系,有多少种可能的排数。

    Input

    包含一个整数,N。

    Output

    包含一个整数,可能的排数。

    Sample Input

    【输入样例一】
    3
    【输入样例二】
    10

    Sample Output

    【输出样例一】
    3
    【输出样例二】
    16

    HINT

    【数据规模和约定】

    100%的数据,满足 1 <= N <= 1000 。

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    隐藏 MOSS 2007 页面版本工具栏
    用于显示原始XML形式的搜索结果的XSLT
    MOSS 2007 日志设置
    在布局页面“文章页面中”添加,自定义UserControl
    MOSS 2007 最简单的自定义搜索框 SearchBox
    Asp.net常用状态管理方案分析
    提高asp.net的性能的几种方法(转)
    VS2005下如何用预编译命令来发布站点
    asp.net控件设计时支持(1)
    解决Enterprise Library January 2006不能加密配置文件的方法(转)
  • 原文地址:https://www.cnblogs.com/chensiang/p/4740695.html
Copyright © 2020-2023  润新知