Number of strings of length N with no palindromic sub string | CPP program to count number of strings of size m such that no substring is palindrome . ; Return the count of strings with no palindromic substring . ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numofstring ( int n , int m ) { if ( n == 1 ) return m ; if ( n == 2 ) return m * ( m - 1 ) ; return m * ( m - 1 ) * pow ( m - 2 , n - 2 ) ; } int main ( ) { int n = 2 , m = 3 ; cout << numofstring ( n , m ) << endl ; return 0 ; }