数字三角形
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>using namespace std;
const int N = 110;
int map[N][N];
int n;int main()
{cin >> n;for(int i=0;i<n;i++){for(int j=0;j<=i;j++){cin >> map[i][j];}}for(int i=n-2;i>=0;i--){for(int j=0;j<=i;j++){if(map[i][j] + map[i+1][j] >=map[i][j] + map[i+1][j+1]){map[i][j] = map[i][j] + map[i+1][j];}else {map[i][j] = map[i][j] + map[i+1][j+1];}}}cout << map[0][0]<<endl;
}
42点问题
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[10];
int n;
char c;
vector<int> ans[10];int main()
{for(int i=0;i<6;i++){cin >> c;switch(c){case 'J':a[i] = 10;break;case 'Q':a[i] = 11;break;case 'K':a[i] = 12;break;case 'A':a[i] = 1;break;default:a[i] = c-'0';}}ans[0].push_back(a[0]);for(int i=1;i<=5;i++){for(int j=0;j<ans[i-1].size();j++){ans[i].push_back(ans[i-1][j] + a[i]);ans[i].push_back(ans[i-1][j] - a[i]);ans[i].push_back(ans[i-1][j] * a[i]);ans[i].push_back(ans[i-1][j] / a[i]);}}bool flag = false;for(int i=0;i<ans[5].size();i++){if(ans[5][i] == 45){flag = true;}if(flag){cout << "YES"<<endl;break;}}if (!flag) cout << "NO"<<endl;return 0;
}