3 条题解
-
1
#include<bits/stdc++.h> using namespace std; long long keep[21][21][21]; long long w(long long a, long long b, long long c) { if(a <= 0||b <= 0||c <= 0)return 1; else if(a > 20||b > 20||c > 20)return w(20, 20, 20); if(keep[a][b][c] != 0)return keep[a][b][c]; if(a < b && b < c) { keep[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c); return keep[a][b][c]; } else { keep[a][b][c] = w(a - 1, b, c)+w(a - 1, b - 1, c)+w(a - 1, b, c - 1)-w(a - 1, b - 1, c - 1); return keep[a][b][c]; } } int main() { long long a[1000], b[1000], c[1000], i = 1; keep[0][0][0]=1; keep[20][20][20]=1048576; for(;; i++) { cin >> a[i] >> b[i] >> c[i]; if(a[i] == -1 && b[i] == -1 && c[i] == -1)break; } for(int j=1; j<i; j++)cout << "w(" << a[j] << ", " << b[j] << ", " << c[j] << ") = " << w(a[j], b[j], c[j]) << "\n"; }
这题解呢,是对的,但是超时了[呜呜呜]
-
1
#include #include using namespace std; typedef long long ll; //手懒得打long long
ll a,b,c,note[30][30][30] = {0}; //记忆初始化,记得都要用ll哦
ll w(ll i,ll j,ll k){ if(i<=0||j<=0||k<=0) return 1; //第一种情况 if(i>20||j>20||k>20) return w(20,20,20);//第二种 if(i<j&&j<k){//第三种 if(note[i][j][k-1] == 0){//是否有记忆 note[i][j][k-1] = w(i,j,k-1); } if(note[i][j-1][k-1] == 0){ note[i][j-1][k-1] = w(i,j-1,k-1); } if(note[i][j-1][k] == 0){ note[i][j-1][k] = w(i,j-1,k); } note[i][j][k] = note[i][j][k-1] + note[i][j-1][k-1] - note[i][j-1][k]; //返回 } else{//其他情况 if(note[i-1][j][k] == 0){ note[i-1][j][k] = w(i-1,j,k); } if(note[i-1][j-1][k] == 0){ note[i-1][j-1][k] = w(i-1,j-1,k); } if(note[i-1][j][k-1] == 0){ note[i-1][j][k-1] = w(i-1,j,k-1); } if(note[i-1][j-1][k-1] == 0){ note[i-1][j-1][k-1] = w(i-1,j-1,k-1); } note[i][j][k] = note[i-1][j][k] + note[i-1][j-1][k] + note[i-1][j][k-1] - note[i-1][j-1][k-1]; } return note[i][j][k];//结束 } int main(){ while(1){ cin>>a>>b>>c; if(a==-1&&b==-1&&c==-1) return 0; cout<<"w("<<a<<", "<<b<<", "<<c<<')'<<" = "<<w(a,b,c)<<endl; } }
-
1
#include #include using namespace std; typedef long long ll; //手懒得打long long
ll a,b,c,note[30][30][30] = {0}; //记忆初始化,记得都要用ll哦
ll w(ll i,ll j,ll k){ if(i<=0||j<=0||k<=0) return 1; //第一种情况 if(i>20||j>20||k>20) return w(20,20,20);//第二种 if(i<j&&j<k){//第三种 if(note[i][j][k-1] == 0){//是否有记忆 note[i][j][k-1] = w(i,j,k-1); } if(note[i][j-1][k-1] == 0){ note[i][j-1][k-1] = w(i,j-1,k-1); } if(note[i][j-1][k] == 0){ note[i][j-1][k] = w(i,j-1,k); } note[i][j][k] = note[i][j][k-1] + note[i][j-1][k-1] - note[i][j-1][k]; //返回 } else{//其他情况 if(note[i-1][j][k] == 0){ note[i-1][j][k] = w(i-1,j,k); } if(note[i-1][j-1][k] == 0){ note[i-1][j-1][k] = w(i-1,j-1,k); } if(note[i-1][j][k-1] == 0){ note[i-1][j][k-1] = w(i-1,j,k-1); } if(note[i-1][j-1][k-1] == 0){ note[i-1][j-1][k-1] = w(i-1,j-1,k-1); } note[i][j][k] = note[i-1][j][k] + note[i-1][j-1][k] + note[i-1][j][k-1] - note[i-1][j-1][k-1]; } return note[i][j][k];//结束 } int main(){ while(1){ cin>>a>>b>>c; if(a==-1&&b==-1&&c==-1) return 0; cout<<"w("<<a<<", "<<b<<", "<<c<<')'<<" = "<<w(a,b,c)<<endl; } }
- 1
信息
- ID
- 5522
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 2
- 标签
- 递交数
- 174
- 已通过
- 51
- 上传者