模拟就行 :
- inline void solve(){
- int n = 0 ;
- for(int a=1;a<=9;a++){
- for(int b=0;b<=9;b++){
- for(int c=0;c<=9;c++){
- if(a>b && b>c){
- n ++ ;
- }
- }
- }
- }
- cout << n << endl ;
- }
直接调用全排列的库函数 , 然后求可能情况 ;
- #include <iostream>
- #include <algorithm>
- using namespace std;
-
- int main() {
- int sum = 0;
- int v[10] = {1,2,3,4,5,6,8,9,10,12};
- do {
- int t = v[0]+v[2]+v[5]+v[8];
- if(t == v[0]+v[3]+v[6]+v[9]
- && t == v[1]+v[2]+v[3]+v[4]
- && t == v[1]+v[5]+v[7]+v[9]
- && t == v[4]+v[6]+v[7]+v[8])
- sum++;
- } while(next_permutation(v, v+10)); //全排列求所有组合
-
- cout << sum/10;
-
- return 0;
- }
推公式,找规律 :
- // 第0年 : t = x ; p = x ;
- // 第一年 : t = x + 2 * x - 1 ; p = 2 * x - 1 ;
- // 第二年 : t = t + 2 * p - 1 ; p = 2 * p - 1 ;
- #include <iostream>
- #include <cmath>
- using namespace std;
-
- int main()
- {
- double n, s;
- cin >> n >> s;
-
- cout << (s - 2 - n + pow(2, n + 1)) / (pow(2, n + 1) - 1) << endl;
- return 0;
- }
- #include <bits/stdc++.h>
- #define MAX 100
- using namespace std;
-
- int n; //代表方阵的大小
- int ans; //记录最优解的步数,初始化一个很大的值
- char arr[MAX][MAX]; //代表方阵中的每一个元素
- int step[MAX][MAX]; //记录从起点到xy点最少走了几步
-
- //x,y代表坐标,刚开始x,y应该代表A的坐标;cnt代表目前移动了几步
- void DFS(int x,int y,int cnt){
- //如果当前步数大于最优解的步数
- if(cnt>ans) return;
- //如果当前步数大于到该点的最少步数
- if(cnt>step[x][y]) return;
- //判断移动的合理性
- if(x<1 ||x>n ||y<1 ||y>n) return;
- //判断是否到达终点
- if(arr[x][y]=='B'){
- //到达终点后,ans记录当前情况下移动的步数,在后面的递归中跟其他情况的移动步数作比较
- ans = cnt;
- return;
- }
-
- step[x][y]=cnt;
-
- int x1,y1;
- x1 = x+1;y1 = y; //右移一格
- if(arr[x1][y1]!=arr[x][y]) DFS(x1,y1,cnt+1);
- x1 = x-1;y1 = y; //左移一格
- if(arr[x1][y1]!=arr[x][y]) DFS(x1,y1,cnt+1);
- x1 = x;y1 = y+1; //上移一格
- if(arr[x1][y1]!=arr[x][y]) DFS(x1,y1,cnt+1);
- x1 = x;y1 = y-1; //下移一格
- if(arr[x1][y1]!=arr[x][y]) DFS(x1,y1,cnt+1);
- }
-
- int main(){
- int x,y;
- ans=INT_MAX;
- cin>>n;
- for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) step[i][j]=INT_MAX;
- for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>arr[i][j];
- //在方阵中找到A的位置
- for(int i=1;i<=n;i++){
- for(int j=1;j<=n;j++){
- if(arr[i][j]=='A'){
- x=i;
- y=j;
- break;
- }
- }
- }
- DFS(x,y,0);
- if(ans==INT_MAX) cout<<-1<<endl;
- else cout<<ans<<endl;
- }
只能过40% ;
- #include<bits/stdc++.h>
- #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define endl '\n'
- typedef long long LL;
- const int mod = 1e9+7;
- const int N = 2e5+10;
- using namespace std;
-
- bool pd(string s){
- int i = 0 , j = s.size() - 1 ;
- while(i < j){
- if(s[i++] != s[j--]) return false ;
- }
- return true ;
- }
-
- inline void solve(){
- int n ; cin >> n ;
- string s ; cin >> s ;
- set<string> e , f ;
- vector<int> a(n) , b(n) ;
- a[0] = 1 ;
- for(int i=0;i<n;i++){
- for(int j=i;j>=0;j-=2){
- int len = i-j+1 ;
- string str = s.substr(j,len) ;
- if(pd(str)) e.insert(str) ;
- }
- a[i] = e.size() ;
- }
- b[n-1] = 0 ;
- for(int i=n-1;i>=0;i--){
- for(int j=i;j<n;j++){
- int len = j-i+1;
- string str = s.substr(i,len) ;
- if(len%2==0 || !pd(str)) f.insert(str) ;
- }
- b[i] = f.size() ;
- }
- int ans = 0 ;
- for(int i=1;i<n;i++){
- ans = max(ans,a[i-1]*b[i]) ;
- }
- cout << ans << endl ;
- }
-
- signed main()
- {
- IOS
- int _ = 1;
- while(_ --) solve();
- return 0;
- }