Created
July 23, 2013 10:17
-
-
Save swapnil-warke/6061366 to your computer and use it in GitHub Desktop.
poj2663,dynamic programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** id :template | |
** author : swap_coder | |
** time: | |
*/ | |
#include<vector> | |
#include<algorithm> | |
#include<cstdio> | |
#include<cstring> | |
#include<cmath> | |
#include <iostream> | |
#include <map> | |
#include <queue> | |
#include <set> | |
#include <string> | |
#include <cstdlib> | |
#include <stack> | |
using namespace std; | |
#define fi(i,a,b) for(int i=(int)a;i<=(int)b;i++) | |
#define fd(i,a,b) for(int i=(int)a;i>=(int)b;i--) | |
#define rep(i,n) for(int i=0;i<n;i++) | |
#define SET(a) memset(a,-1,sizeof(a)) | |
#define ALL(a) a.begin(),a.end() | |
#define CLR(a) memset(a,0,sizeof(a)) | |
#define FILL(a,v) memset(a,v,sizeof(a)) | |
#define READ(f) freopen(f, "r", stdin) | |
#define WRITE(f) freopen(f, "w", stdout) | |
#define INF (1<<29) | |
#define EPS 1e-9 | |
#define PI acos(-1.0) | |
//stl | |
#define sz(a) int((a).size()) | |
#define pb push_back | |
#define all(c) ((c).begin(),(c).end()) | |
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) | |
#define present(c,x) ((c).find(x) != (c).end()) | |
#define cpresent(c,x) (find(all(c),x) != (c).end()) | |
#define pf printf | |
#define sf scanf | |
typedef long long ll; | |
typedef vector<int> vi; | |
typedef pair<int, int> ii; | |
typedef vector<ii> vii; | |
typedef vector<vi> vvi; | |
typedef vector<vii> vvii; | |
typedef map<string,int> msi; | |
int main() | |
{ | |
int t; | |
int a[40],d[40]; | |
rep(i,40)a[i]=d[i]=0; | |
a[0]=d[1]=0; | |
d[0]=a[1]=1; | |
fi(i,2,31) | |
{ | |
a[i]=d[i-1]+a[i-2]; | |
d[i]=2*a[i-1]+d[i-2]; | |
} | |
while(1) | |
{ | |
cin>>t; | |
if(t==-1) break; | |
cout<<d[t]<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment