using namespace std; #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<limits> #include<cmath> #include<queue> #include<map> #define LLU long long unsigned int #define LLD long long double #define FOR(i,N) for(int i=0;i<(N);i++) int main() { int N,t,k; while(cin>>N && N) { vector<int> inp; FOR(i,N) { cin>>t; inp.push_back(t); } cin>>k; vector<int> res; res.push_back(inp[inp.size()-1]); for(int i=0;i<N-1;i++) { for(int j=N-1;j>i;j–) { inp[j]=inp[j]-inp[j-1]; } res.push_back(inp[N-1]); } for(int j=0;j<k;j++) { for(int i=res.size()-2;i>=0;i–) { res[i]=res[i]+res[i+1]; } } printf(“Term %d of the sequence is %d\n”,N+k,res[0]); } }
Saturday, 18 January 2014
UVA 326
Labels:
uva
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment