Perfect Spring AK Code

1. The frog climbs the stairs, the classic DP problem, the change is that it cannot jump continuously

  所以 dp[i] =dp[i-1]+dp[i-3];

  Magical default input method

#include<bits/stdc++.h>
using namespace std;
#define LOACL  freopen("in","r",stdin);\
         freopen("out","w",stdout); 
#define FASTIO  ios::sync_with_stdio(false);
#define CLOCK cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";


const int   inf = 987654321;
const int    sz = (int)1e6 + 5;
const int   mod = (int)1e9 + 7;
const int sqrtn = 300; 

//#define add(u,v,w) (e[++tot]=(edge){v,head[u],1},head[u]=tot;) 
#define CLR(arr,val) memset(arr,val,sizeof(arr)) 
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define DBG2(x,y) cout<<(#x)<<"="<<x<<"\t"<<(#y)<<"="<<y<<endl
#define DBG3(x,y,z) cout<<(#x)<<"="<<x<<"\t"<<(#y)<<"="<<y<<"\t"<<(#z)<<"="<<z<<endl

#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)


#define all(x) x.begin(),x.end()
#define low(x) (x)&(-x)
#define pb push_back
typedef long long ll; 
typedef double dl; 
int dp[55];
int jump(int num)
{
    return dp[num];
}
intmain ()
{
    LOACL
      dp[0]=1;
      dp[1]=1;dp[2]=2;
      REP(i,3,54)
      {
          dp[i]+=dp[i-1];
          dp[i]+= dp[i-3] ; 
      }
       //REP(i,1,54) DBG2(i,dp[i]);


 
    string line;
    while(getline(cin, line))
    {
        stringstream ss(line);
        int num = 0 ;
        ss >> num;
        if(num == 0) break;
        cout << jump(num) << endl;
    }
 
    return 0;
}
View Code

2. n people do n seats not their own. There is one extra person who does it right

  Number Theory Problem dp[i] =(i-1)*(dp[i-1]+dp[i-2])

#include<bits/stdc++.h>
using namespace std;
#define LOACL  freopen("in","r",stdin);\
         freopen("out","w",stdout); 
#define FASTIO  ios::sync_with_stdio(false);
#define CLOCK cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";


const int   inf = 987654321;
const int    sz = (int)1e6 + 5;
const int   mod = (int)1e9 + 7;
const int sqrtn = 300; 

//#define add(u,v,w) (e[++tot]=(edge){v,head[u],1},head[u]=tot;) 
#define CLR(arr,val) memset(arr,val,sizeof(arr)) 
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define DBG2(x,y) cout<<(#x)<<"="<<x<<"\t"<<(#y)<<"="<<y<<endl
#define DBG3(x,y,z) cout<<(#x)<<"="<<x<<"\t"<<(#y)<<"="<<y<<"\t"<<(#z)<<"="<<z<<endl

#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)


#define all(x) x.begin(),x.end()
#define low(x) (x)&(-x)
#define pb push_back
typedef long long ll; 
typedef double dl; 
int dp[70];
int ff(int n)
{
    if(n<0) return 0;
    if(n==1) return 1 ;
    if(n==2) return 0;
     
    return  n*dp[n-1];

}
intmain ()
{
    LOACL
    dp[0]=dp[1]=0;
    dp[2]= 1;
    REP(i,3,66)
    {
        dp[i]=(i-1)*(dp[i-1]+dp[i-2]);
    }
   //  REP(i,2,66) DBG(dp[i]);
    int n;
    while(cin>>n)
        cout<<ff(n)<<endl;

    return 0;
}
View Code

 

It seems that this spring recruiting, I can't find a place to practice, like attacking the field of machine learning, it is difficult to become a dog, and it may not be fruitful, but so what?

My throat is inflamed and it hurts. I have nowhere to complain. Fortunately, I am in a good mood.

I'm afraid it's not that my Buddhist life is really becoming more and more real. I cry alone, true love is invincible, I miss you

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981422&siteId=291194637