[DP] Codechef .Chef And Fibonacci Array
2017-08-18 21:11
351 查看
chuansongmen
首先有一个O(m5)的DP,其中m为变换后可取到的最大值。
然后猜猜猜
发现每个数,最多加前两个数中的最小值,那么就猜不存在一种变换,使其中一个数大于100,写完DP后assert了一下,发现RE了…
那么就猜不大于150,就过了…
转移的时候去掉无效的转移常数就贼小
首先有一个O(m5)的DP,其中m为变换后可取到的最大值。
然后猜猜猜
发现每个数,最多加前两个数中的最小值,那么就猜不存在一种变换,使其中一个数大于100,写完DP后assert了一下,发现RE了…
那么就猜不大于150,就过了…
转移的时候去掉无效的转移常数就贼小
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <assert.h> using namespace std; const int N=160,P=1e9+7; int t,n,a ,f ; inline void add(int &x,int y){ if((x+=y)>=P) x-=P; } int main(){ scanf("%d",&t); while(t--){ memset(f,0,sizeof(f)); memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); if(n==1){ printf("%d\n",1); continue; } f[2][a[2]][a[1]]=1; for(int i=2;i<=150;i++) for(int j=0;j<=150;j++) for(int k=0;k<=150;k++) if(f[i][j][k]) for(int s=0;s<=j && s<=k;s++){ assert(a[i+1]+s<=150); add(f[i+1][a[i+1]+s][j-s],f[i][j][k]); } printf("%d\n",f[100][0][0]); } return 0; }
相关文章推荐
- CodeChef Cards, bags and coins [DP 泛型背包]
- codeforces D. Levko and Array(二分加dp) 挺好的一个题
- CodeChef:Company and Club Hierarchies(树形dp & 技巧)
- CodeChef:Girl Friend and String Gift(dp)
- CodeChef Mahesh and his lost array
- codechef AUG17 T5 Chef And Fibonacci Array
- CodeChef Sereja and Game [DP 概率 博弈论]
- 【欧拉筛+主席树】CodeChef PRMQ Chef and Prime Queries
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
- CodeChef - FNCS Chef and Churu(分块)
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
- Kefa and Dishes CodeForces - 580D (dp 状态压缩)
- E. Vladik and cards Codeforces Round #384 (Div. 2) 好题 二分+(贪心+状态压缩DP)判断
- codechef Jewels and Stones 题解
- Codechef TREEPATH 线段树优化dp+dsu on tree
- codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
- Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks(矩阵优化DP)
- codeforce Ilya and Roads (区间dp)
- JS code do conversion between hexStr and byteArray
- CodeChef SEAVOTE Sereja and Votes