4fd800b3a8 2011-02-23 kinaba: // Tested: SRM 454 Lv2 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP2 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: const int N1, N2; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP2(int N1, int N2, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(N1), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2) 4fd800b3a8 2011-02-23 kinaba: { return data[ (i1*N2)+i2 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP2& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Tested: Codeforces #13 C 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP2x 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: const int N1, N2; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP2x(int, int N2, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(2), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2) 4fd800b3a8 2011-02-23 kinaba: { i1&=1; return data[ (i1*N2)+i2 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP2x& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Tested: SRM 452 Lv3 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP3 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N1, N2, N3; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP3(int N1, int N2, int N3, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(N1), N2(N2), N3(N3), data(N1*N2*N3, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2, int i3) 4fd800b3a8 2011-02-23 kinaba: { return data[ ((i1*N2)+i2)*N3+i3 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP3& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Tested: SRM 468 Lv2 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP3x 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N1, N2, N3; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP3x(int, int N2, int N3, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(2), N2(N2), N3(N3), data(N1*N2*N3, t) { assert(data.size()*sizeof(T) < (1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2, int i3) 4fd800b3a8 2011-02-23 kinaba: { i1&=1; return data[ ((i1*N2)+i2)*N3+i3 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP3x& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Not Tested 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP4 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N1, N2, N3, N4; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP4(int N1, int N2, int N3, int N4, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(N1), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2, int i3, int i4) 4fd800b3a8 2011-02-23 kinaba: { return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP4& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Not Tested 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP4x 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N1, N2, N3, N4; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP4x(int, int N2, int N3, int N4, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(2), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2, int i3, int i4) 4fd800b3a8 2011-02-23 kinaba: { i1&=1; return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP4x& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Tested: SRM 351 Lv2 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP5 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N1, N2, N3, N4, N5; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP5(int N1, int N2, int N3, int N4, int N5, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(N1), N2(N2), N3(N3), N4(N4), N5(N5), data(N1*N2*N3*N4*N5, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2, int i3, int i4, int i5) 4fd800b3a8 2011-02-23 kinaba: { return data[ ((((i1*N2)+i2)*N3+i3)*N4+i4)*N5+i5 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP5& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Not Tested 4fd800b3a8 2011-02-23 kinaba: template<typename T> 4fd800b3a8 2011-02-23 kinaba: struct DP5x 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N1, N2, N3, N4, N5; 4fd800b3a8 2011-02-23 kinaba: vector<T> data; 4fd800b3a8 2011-02-23 kinaba: DP5x(int, int N2, int N3, int N4, int N5, const T& t = T()) 4fd800b3a8 2011-02-23 kinaba: : N1(2), N2(N2), N3(N3), N4(N4), N5(N5), data(N1*N2*N3*N4*N5, t) { assert(data.size()*sizeof(T)<(1<<26)); } 4fd800b3a8 2011-02-23 kinaba: T& operator()(int i1, int i2, int i3, int i4, int i5) 4fd800b3a8 2011-02-23 kinaba: { i1&=1; return data[ ((((i1*N2)+i2)*N3+i3)*N4+i4)*N5+i5 ]; } 4fd800b3a8 2011-02-23 kinaba: void swap(DP5x& rhs) 4fd800b3a8 2011-02-23 kinaba: { data.swap(rhs.data); } 4fd800b3a8 2011-02-23 kinaba: };